-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1049.py
More file actions
32 lines (26 loc) · 652 Bytes
/
Copy path1049.py
File metadata and controls
32 lines (26 loc) · 652 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import sys
N, M = map(int,sys.stdin.readline().split())
brands = []
brands_string = []
for i in range(M):
temp = list(map(int,sys.stdin.readline().split()))
brands.append(temp)
brands_string.append(temp)
brands.sort()
brands_string.sort(key = lambda x: (x[1], x[0]))
#print(brands)
#print(brands_string)
cost1, cost2 = brands[0][0], brands_string[0][1]
if N <= 6:
if cost1 < cost2 * N:
print(cost1)
else:
print(cost2*N)
else:
if N%6 == 0:
new_cost1 = cost1* (N//6)
else:
new_cost1 = cost1* (N//6 + 1)
new_cost2 = cost2 * N
new_cost3 = cost1 * (N//6) + cost2 * (N%6)
print(min(new_cost1,new_cost2,new_cost3))