#f = open('27.txt') #f = open('27_A.txt') f = open('27_B.txt') a = [] fl = 0 for i in f: if fl == 0: pass fl = 1 else: a.append(i.split()) for i in a: i[0] = int(i[0]) i[1] = int(i[1]) #a = [[1,100],[2,200],[5,4],[7,3],[8,2],[10,190]] #b = 96 b = 36 smax = 0 nsum = 0 for i in a: s = i[0] if i[1]%b == 0: n = i[1]//b else: n = i[1]//b+1 p = s*n #print(p) smax = smax + p nsum = nsum + n #print(smax) #print(nsum) rez = 1000000000000000000 nold_sum = 0 sold = 0 sdelt = 0 sdelt2 = 0 nold=0 for i in a: #print('=====') s = i[0] if i[1]%b == 0: n = i[1]//b else: n = i[1]//b+1 p = smax - (nsum-nold_sum) * s sdelt = sdelt + nold * sold skv = nold_sum * s sdelt2 = (skv - sdelt) p = p - sdelt + sdelt2 #print(p) if p < rez: rez = p nold = n sold = s nold_sum = nold_sum + n print('ответ = ',rez)