Skip to content

Commit 1e204dd

Browse files
Add files via upload
1 parent c7a5aba commit 1e204dd

File tree

6 files changed

+141
-0
lines changed

6 files changed

+141
-0
lines changed

Week 3/Max ad revenue.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
n = int(input())
2+
a = [int(i) for i in input().split()]
3+
b = [int(i) for i in input().split()]
4+
a.sort()
5+
b.sort()
6+
ans = sum([a[i]*b[i] for i in range(n)])
7+
print(ans)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
n, W = [int(i) for i in input().split()]
2+
lst = []
3+
4+
if W == 0:
5+
print(0)
6+
quit()
7+
8+
for _ in range(n):
9+
v, w = [int(i) for i in input().split()]
10+
if v == 0:
11+
continue
12+
lst.append((v, w))
13+
14+
lst.sort(key = lambda x: x[0]/x[1], reverse = True)
15+
16+
total_value = 0
17+
18+
for v,w in lst:
19+
if W==0:
20+
print(total_value)
21+
quit()
22+
amt = min(w, W)
23+
total_value += amt*v/w
24+
W -= amt
25+
26+
print(total_value)

Week 3/Maximum prizes greedy.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Wed Aug 26 20:43:05 2020
4+
5+
@author: 91842
6+
"""
7+
n = int(input())
8+
9+
10+
ans = []
11+
12+
if n==1:
13+
print(1)
14+
print(1)
15+
quit()
16+
17+
w=n
18+
for i in range(1, n):
19+
if w>2*i:
20+
ans.append(i)
21+
w=w-i
22+
else:
23+
ans.append(w)
24+
break
25+
26+
27+
28+
print(len(ans))
29+
print(' '.join([str(i) for i in ans]))
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Sat Aug 22 19:57:40 2020
4+
5+
@author: 91842
6+
"""
7+
8+
arr = []
9+
B = int(input()) #maximum distance traversed in 1 full tank
10+
L = int(input()) #destination
11+
n=int(input())
12+
arr = list(map(int, input().split()))
13+
14+
arr.insert(0,int(0))
15+
arr.append(B)
16+
17+
def MinRefills(x,n,L):
18+
numrefills = 0
19+
currentrefills = 0
20+
while currentrefills<=n:
21+
lastrefill = currentrefills
22+
while currentrefills<=n and x[currentrefills+1]-x[lastrefill]<=L:
23+
currentrefills = currentrefills+1
24+
if currentrefills == lastrefill:
25+
return -1
26+
if currentrefills<=n:
27+
numrefills=numrefills+1
28+
return numrefills
29+
30+
ans = MinRefills(arr,n,L)
31+
32+
print(ans)

Week 3/Money Change.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Sun Aug 23 16:02:05 2020
4+
5+
@author: 91842
6+
"""
7+
from math import floor
8+
m = int(input())
9+
count1 = 0;count2=0;count3=0
10+
if m>=10:
11+
count1 = floor(m/10)
12+
m=m%10
13+
14+
15+
if m>=5 and m<10:
16+
count2 = 1
17+
m=m-5
18+
19+
20+
21+
if m>=1 and m<5:
22+
count3 = m
23+
24+
ans = count1+count2+count3
25+
print(ans)
26+
27+

Week 3/signature.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
n = int(input())
2+
lst = []
3+
4+
for _ in range(n):
5+
a, b = [int(i) for i in input().split()]
6+
lst.append((a,b))
7+
8+
lst.sort(key = lambda x: x[1])
9+
10+
index = 0
11+
coordinates = []
12+
13+
while index < n:
14+
curr = lst[index]
15+
while index < n-1 and curr[1]>=lst[index+1][0]:
16+
index += 1
17+
coordinates.append(curr[1])
18+
index += 1
19+
print(len(coordinates))
20+
print(' '.join([str(i) for i in coordinates]))

0 commit comments

Comments
 (0)