Problem:


Score : 300 points

Problem Statement

Hearing that energy drinks increase rating in those sites, Takahashi decides to buy up M cans of energy drinks.

There are N stores that sell energy drinks. In the i-th store, he can buy at most B_i cans of energy drinks for A_i yen (the currency of Japan) each.

What is the minimum amount of money with which he can buy M cans of energy drinks?

It is guaranteed that, in the given inputs, a sufficient amount of money can always buy M cans of energy drinks.

Constraints

All values in input are integers.

1 \leq N, M \leq 10^5

1 \leq A_i \leq 10^9

1 \leq B_i \leq 10^5

B_1 + ... + B_N \geq M

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
A_2 B_2
\vdots
A_N B_N

Output

Print the minimum amount of money with which Takahashi can buy M cans of energy drinks.

Sample Input 1

2 5
4 9
2 4

Sample Output 1

12

With 12 yen, we can buy one drink at the first store and four drinks at the second store, for the total of five drinks. However, we cannot buy 5 drinks with 11 yen or less.

Sample Input 2

4 30
6 18
2 5
3 10
7 9

Sample Output 2

130

Sample Input 3

1 100000
1000000000 100000

Sample Output 3

100000000000000

The output may not fit into a 32-bit integer type.



Sample input:
2 5
4 9
2 4


Sample output:
12

Submission status: Wrong Answer

Solution code:
from sys import stdin
import heapq
hq = []  

NM = input()
NM = NM.split()
N = int(NM[0])
M = int(NM[1])

hq = []
AB = {}
for i in range(N):
  temp = input()
  temp = temp.split()
  AB[int(temp[0])] = int(temp[1])
  heapq.heappush(hq, (int(temp[0]), int(temp[1])))

print(hq)
cost = 0
amount = 0
for i in range(N):
  if amount + hq[i][1] < M:
    amount += hq[i][1]
    cost += hq[i][0]*hq[i][1]
  else:
    temp = M - amount
    cost += hq[i][0]*temp
    break
    
print(cost)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
drink_dict = {}
for i in range(N):
  A,B = map(int,input().split())
  if A not in drink_dict:
  	drink_dict[A] = B
  else:
    drink_dict[A] += B 
drink_list = sorted(drink_dict.items())
total_number = 0
total_price = 0
for i in drink_list:
  if total_number + i[1] >= M:
    print(total_price + (M-total_number) * i[0])
  else:
    total_price+=i[0]*i[1]
    total_number+= i[1]

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
drink_dict = {}
for i in range(N):
  A,B = map(int,input().split())
  if A not in drink_dict:
  	drink_dict[A] = B
  else:
    drink_dict[A] += B 
total_number = 0
total_price = 0
for price,number in drink_dict.items():
  if total_number + number >= M:
    print(total_price + (M-total_number) * price)
  else:
    total_price+=price*number
    total_number+= number

Submission status: Wrong Answer

Solution code:
n,m,*t = map(int, open(0).read().split())
ans = 0
for a, b in sorted(zip(t[::2], t[1::2])):
  ans += min(a, m)*b
  m -= a
  if m <= 0:
    print(ans)
    break;

Submission status: Wrong Answer

Solution code:
list1 = raw_input().split()

N = long(list1[0])

M = long(list1[1])

AB_list = []

for n in range(N):
    item = raw_input().split()
    AB_list.append(item)

AB_list.sort()

money = 0
drink = 0


for x in range(N):
    for b in range(long(AB_list[x][1])):
        money += long(AB_list[x][0])
        drink += 1
        if drink >= M:
            break
    if drink >= M:
        break

print money

Submission status: Wrong Answer

Solution code:
list1 = raw_input().split()

N = int(list1[0])

M = int(list1[1])

AB_list = []

for n in range(N):
    item = raw_input().split()
    AB_list.append(item)

AB_list.sort()

money = 0
drink = 0


for x in range(N):
    for b in range(int(AB_list[x][1])):
        money += int(AB_list[x][0])
        drink += 1
        if drink >= M:
            break
    if drink >= M:
        break

print money

Submission status: Wrong Answer

Solution code:
N,M = map(int, input().split())
import numpy as np
AB = np.sort([list(map(int, input().split())) for _ in range(N)],axis=0)
l = []
for a,b in AB:
  l.extend([a]*b)
  if len(l) > M:
    break
print(sum(sorted(l)[:M]))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

sorted_ab = sorted(AB)
cost = 0

for i in range(N):
      for j in range(sorted_ab[i][1]):
            M -= 1
            cost += sorted_ab[i][0]
            if M == 0:
              break
print(cost)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=[]
b=[]
for i in range(n):
  s,t=map(int,input().split())
  a.append(s)
  b.append(t)
c=sorted(a)
d=[0]*n
for j in range(n):
  d[j]=b[a.index(c[j])]
cnt=0
totl=0
for l in range(n):
  if cnt==m:
      print(totl)
      break
  if cnt>m:
      print(totl-(cnt-m)*c[l-1])
      break
  else:
    totl+=c[l]
    cnt+=d[l]

Submission status: Wrong Answer

Solution code:
li_a = []
ans = 0
N,M = map(int,input().split())
for i in range(N):
    a,b = map(int,input().split())
    li_a +=[[a,b]]
li_a.sort()
for i in range(N):
    if li_a[i][-1] >= M:
        ans += M * li_a[i][0]
        print(ans)
    else:
        ans += li_a[i][-1] * li_a[i][0]
        M -= li_a[i][-1]

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from operator import itemgetter

s = input().rstrip().split(' ')
n, m = int(s[0]),int(s[1])

stores = []
for i in range(n):
    store = input().rstrip().split(' ')
    stores.append(store)

stores.sort(key=itemgetter(0))
price = 0
count = 0

for j in range(n):
    if count == m:
        break
    for k in range(int(stores[j][1])):
        if count < m:
            price += int(stores[j][0])
            count += 1
        else:
            break

print(price)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from operator import itemgetter

s = input().rstrip().split(' ')
n, m = int(s[0]),int(s[1])

stores = []
for i in range(n):
    store = input().rstrip().split(' ')
    stores.append(store)

stores.sort(key=itemgetter(0))
price = 0
count = 0

for j in range(n):
    for k in range(int(stores[j][1])):
        if count < m:
            price += int(stores[j][0])
            count += 1
        else:
            break

print(price)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

from operator import itemgetter

s = input().rstrip().split(' ')
n, m = int(s[0]),int(s[1])

stores = []
for i in range(n):
    store = input().rstrip().split(' ')
    stores.append(store)

stores.sort(key=itemgetter(0))
price = 0
count = 0

for j in range(n):
    for k in range(int(stores[j][1])):
        price += int(stores[j][0])
        count += 1
        if count is m:
            break;

print(price)

Submission status: Wrong Answer

Solution code:
n, m = [int(i) for i in input().split()]
dat = [[int(i) for i in input().split()] for i in range(n)]
dat.sort()
sum = 0
_m = 0
for i in dat:
    if _m + i[1] > m:
        print(sum + i[0]*(m - _m))
        break
    _m += i[1]
    sum += i[0] * i[1]

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())

list_tmp = []
list_A = []
dict_AB = {}
for i in range(N):
    A, B = map(int, input().split())
    if dict_AB.get(A) is None:
        dict_AB[A] = B
    else:
        list_tmp.append((A, B))
    list_A.append(A)

list_A.sort()

ct = 0
money = 0
for i in list_A:
    A = i
    if list_tmp:
        for j in list_tmp:
            if j[0] == i:
                B = j[1]
                list_tmp.remove((i, B))
                list_A.remove(i)
            else:
                B = dict_AB[i]
    else:
        B = dict_AB[i]
    for j in range(B):
        money += A
        ct += 1
        if ct == M:
            break
    if ct == M:
        break

print(money)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,M=[int(i) for i in input().split()]
a=[]
for j in range(N):
  a.append([int(i) for i in input().split()])

a.sort(key=lambda x:x[0])

cost=0
shop=0
for j in range(M):
  if a[shop][1]==0:
    shop+=1
  else:
    a[shop][1]-=1
    cost+=a[0][0]
print(cost)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
list = [list(map(int,input().split())) for _ in range(N)]
list.sort()

cnt = 0
sum = 0

for i in range(N):
    if cnt + list[i][1] <= M:
        cnt += list[i][1]
        sum += list[i][1]*list[i][0]
    else:
        sum += (M-cnt)*list[i][0]
        break

print(cnt,sum)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, M = map(int, input().split())
AB = np.empty((N, 2), dtype=np.int64)
for n in range(N):
    AB[n, :] = list(map(int, input().split()))
AB = AB[AB[:, 0].argsort(), :]
print(AB)
n = 0
ans = 0
while M > 0:
    if M > AB[n, 1]:
        ans += AB[n, 0] * AB[n, 1]
        M -= AB[n, 1]
    else:
        ans += AB[n, 0] * M
        M = 0
    n += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools, copy
A, B = [], []
N, M = (int(x) for x in input().split())
for i in range(N):
    a, b = (int(x) for x in input().split())
    A.append(a)
    B.append(b)

Max = 0
for i in range(N):
    Max += A[i] * B[i]

def SumOfList(list):
    ret = 0
    for i in list:
        ret += i
    return ret

def TotalFee(list):
    ret, index = 0, 0
    for z in list:
        ret += A[index] * z
        index += 1
    return ret

def DivToList(divList):
    temp = 0
    retList = []
    for x in divList:
        if x == 1:
            retList.append(temp)
            temp = 0
        elif x == 0:
            temp += 1
    retList.append(temp)
    return retList

def DivisionChecker(divList):
    temp, index = 0, 0
    List = DivToList(divList)
    checker = True
    for x in List:
        if x > B[index]:
            checker = False
            break
        else:
            index += 1
    return checker

def SwapEndOfDivList(divList):
    retList = divList
    Length = len(divList)
    j = Length - 1
    if divList[j] == 1:
        for i in range(1, Length):
            j += -1
            if divList[j] == 1:
                continue
            else:
                break
    if divList[j] == 0:
        for i in range(1, Length):
            j += -1
            if divList[j] == 0:
                continue
            else:
                retList[j] = 0
                retList[j+1] = 1
                break
    return retList

def AllDivList(X, Y):
    retList, tempDivList, EndDivList = [], [], []
    for i in range(X-1):
        tempDivList.append(1)
    for j in range(Y):
        tempDivList.append(0)
        EndDivList.append(0)
    for i in range(X-1):
        EndDivList.append(1)
    while True:
        if DivisionChecker(tempDivList) == True:
            CopiedList = copy.copy(tempDivList)
            retList.append(CopiedList)
        tempDivList = SwapEndOfDivList(tempDivList)
        if tempDivList == EndDivList:
            if DivisionChecker(tempDivList) == True:
                CopiedList = copy.copy(tempDivList)
                retList.append(CopiedList)
            break
    return retList

#list of all l such that SumOfList(l) == M
List = []
for l in AllDivList(N, M):
    List.append(DivToList(l))


for l in List:
    if TotalFee(l) < Max:
        Max = TotalFee(l)

print(Max)

Submission status: Wrong Answer

Solution code:
n, m = (int(i) for i in input().split())
a = [list(map(int,input().split())) for i in range(n)]
b = sorted(a)
cnt = 0
money = 0
print(b)

while True:
	for x,y in b:
		cnt += y
		money += x * y
		print(money)
		if m < cnt:
			money -= (cnt - m)*x
			print(money)
			exit()

Submission status: Wrong Answer

Solution code:
N,M = map(int, raw_input().split())
ab = [[0 for i in range(2)] for j in range(N)]
for i in range(N):
    ab[i][0], ab[i][1] = map(int, raw_input().split())
AB = sorted(ab, key=lambda x:x[0])
count = 0
total = 0
for i in range(N):
    for j in range(AB[i][1]):
        if count < M:
            total += AB[i][0]
            count += 1
        else:
            exit()

print total

Submission status: Wrong Answer

Solution code:
N,M = map(int, raw_input().split())
ab = [[0 for i in range(2)] for j in range(N)]
for i in range(N):
    ab[i][0], ab[i][1] = map(int, raw_input().split())
AB = sorted(ab, key=lambda x:x[0])
count = 0
total = 0
for i in range(N):
    for j in range(AB[i][1]):
        if count < M:
            total += AB[i][0]
            count += 1
        else:
            print total
            exit()

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
AB = []
for i in range(N):
    Ai, Bi = map(int, input().split())
    AB.append([Ai, Bi])

# Bubble Sort
start = 0
for i in range(N-1):
    for index in range(start, N-1):
        if AB[index][0] > AB[index+1][0]:
            AB[index], AB[index+1] = AB[index+1], AB[index]
        else:
            pass
        start += 1

final = 0
sum_bottles = 0
while(M > sum_bottles):
    final += 1
    sum_bottles = 0
    for i in range(final):
        sum_bottles += AB[i][1]

cost = 0
bottles = 0
for i in range(final):
    if i == final - 1:
        cost += AB[i][0] * (M - bottles)
    else:
        cost += AB[i][0] * AB[i][1]
        bottles += AB[i][1]

print(cost)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
pay_rank = []
    
for n in range(N):
  A,B = map(int,input().split())
  pay_rank.append([A,B])
pay_rank.sort()

buy = []
for n in pay_rank:
  if M >= n[1]:
    M -= n[1]
    buy.append([n[0],n[1]])
  else:
    for b in range(n[1]):
      if M == b:
        buy.append([n[0],b])
      
sum = 0
for i in buy:
  sum += i[0]*i[1]
print(sum)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
sum_list = []

for n in range(N):
  A,B = map(int,input().split())
  one_store = 0
  for b in range(B):
      one_store += A*b
  sum_list.append(one_store)
print(min(sum_list))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a, b = zip(*(map(int, input().split()) for _ in range(n)))
c = sorted(zip(a, b))

cost = 0
rest = m
for a, b in c:
    if m >= b:  # bを足すだけの余裕があるとき
        cost += a * b
        rest -= b
    else:  # b本は買えないとき買えるのはm本
        cost += a * m
        break
print(cost)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
dataset=sorted([tuple(map(int,input().split())) for i in range(n)])
ans=0
for data in dataset:
  if m==0:
    print(ans)
    exit()
  tmp=min(data[1],m)
  ans+=tmp*data[0]
  m-=tmp

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M = map(int, input().split())
num_dict = dict()
A_list = []
B_list = []

for n in range(N):
  A, B = map(int, input().split())
  num_dict[A] = B
  A_list.append(A)

A_list.sort()
b_accum = 0
all_pay = 0

for a in A_list:
  if M <= b_accum:
    break

  if b_accum + num_dict[a] <= M:
    all_pay += num_dict[a] * a
    b_accum += num_dict[a]    
  
  else:
    all_pay += (M - b_accum) * a 
    b_accum += num_dict[a]
    break
    
print(all_pay)

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M = map(int, input().split())
num_dict = dict()
A_list = []

for n in range(N):
  A, B = map(int, input().split())
  num_dict[A] = B
  A_list.append(A)

A_list.sort()
b_accum = 0
all_pay = 0

for a in A_list:
  if M <= b_accum:
    break

  if b_accum + num_dict[a] <= M:
    all_pay += num_dict[a] * a
    b_accum += num_dict[a]    
  
  else:
    all_pay += (M - b_accum) * a 
    b_accum += num_dict[a]
    
print(all_pay)

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M = map(int, input().split())
num_dict = dict()
A_list = []

for n in range(N):
  A, B = map(int, input().split())
  num_dict[A] = B
  A_list.append(A)

A_list.sort()
b_accum = 0
all_pay = 0

for a in A_list:

  if b_accum + num_dict[a] <= M:
    all_pay += num_dict[a] * a
    b_accum += num_dict[a]
    
    if M == b_accum:
      break
  
  else:
    all_pay += (M - b_accum) * a 
    break

   
print(all_pay)

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M = map(int, input().split())
num_dict = dict()
A_list = []

for n in range(N):
  A, B = map(int, input().split())
  num_dict[A] = B
  A_list.append(A)

A_list.sort()
b_accum = 0
all_pay = 0

for a in A_list:

  if b_accum + num_dict[a] <= M:
    all_pay += num_dict[a] * a
    b_accum += num_dict[a]
  
  else:
    all_pay += (M - b_accum) * a 
    break

   

print(all_pay)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())

money = float(0)

kakaku = []
honsuu = []
nokori_honsuu = M

for i in range(N):
	A, B = map(int, input().split())
	kakaku.append(A)
	honsuu.append(B)

while nokori_honsuu > 0:
	min_kakaku_pos = kakaku.index(min(kakaku))
	if honsuu[min_kakaku_pos] <= nokori_honsuu:
		money += honsuu[min_kakaku_pos] * kakaku[min_kakaku_pos]
		nokori_honsuu -= honsuu[min_kakaku_pos]
	else:
		money += nokori_honsuu * kakaku[min_kakaku_pos]
		nokori_honsuu -= nokori_honsuu
	kakaku.pop(min_kakaku_pos)
	honsuu.pop(min_kakaku_pos)
print(money)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, M = list(map(int, input().split()))
data = []
for i in range(N):
  data.append(list(map(int, input().split())))
data = np.asarray(data)
data = np.sort(data, axis=0)

res = 0
for info in data:
  for i in range(info[1]):
    M -= 1
    res += info[0]
    if M==0:
      break
  if M==0:
    break
print(res)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N,M =map(int, input().split())
b=[]
for _ in range(N):
    a=list(map(int, input().split()))
    b.append(a)

b.sort(key=itemgetter(0))
#print('ソート後(0番目の要素)：{}'.format(b))

c=0 #個数
d=0 #値段
for i in range(N):
    c+=b[i][1]
    d+=b[i][0]*b[i][1]
    if c>M:
        d-=(c-M)*b[i][0]
        break
print(d)
print(c)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N,M =map(int, input().split())
b=[]
for _ in range(N):
    a=list(map(int, input().split()))
    b.append(a)

b.sort(key=itemgetter(0))
print('ソート後(0番目の要素)：{}'.format(b))

c=0
d=0
for i in range(N):
    c+=b[i][1]
    d+=b[i][0]*b[i][1]
    if c>M:
        d-=(c-M)*b[i][0]
print(d)

Submission status: Wrong Answer

Solution code:
N,M = (int(_) for _ in input().split())
shops = []
NumberOfEDWillBuy = []
for i in range(N):
    price,stock = (int(_) for _ in input().split())
    shops.append((price,stock))
#map(int,input().split())はmapobjectを返す
#(int(_) for _ in input().split())はgenerator objectを返す
#iteratorしかsorted関数は使えないので、一度priceとstockにアクセスする形にしてshopsを
#generatorのlistにならないようにしている。
NumberOfEDWanted = N
sortedShops = sorted(shops,key = lambda shop:shop[0])
for shop in sortedShops:
    if NumberOfEDWanted < shop[1]:
        NumberOfEDWillBuy.append(NumberOfEDWanted)
    else:
        NumberOfEDWillBuy.append(shop[1])
        NumberOfEDWanted -= shop[1]
sum = 0
for i in range(len(NumberOfEDWillBuy)):
    sum += sortedShops[i][0]*NumberOfEDWillBuy[i]
print(sum)

Submission status: Wrong Answer

Solution code:
N, M = map(int,input().split())
AB = sorted([list(map(int,input().split())) for _ in range(N)])

money = 0
for a, b in AB:
  if(M-b >= 0):
    money += a*b
    M -= b
  else:
    money += a*M
    M -= M-b
print(money)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())

X=[]

for i in range(n):
    X.append(list(map(int,input().split())))

Y=sorted(X,key=lambda x:x[0])

cnt=0
ans=0
for i in range(n):
    ad=Y[i][1]
    temp=cnt
    cnt+=ad
    if cnt+ad>m:
        ad=m-temp
        ans+=Y[i][0]*ad
        break
    ans+=Y[i][0]*ad

print(ans)

Submission status: Wrong Answer

Solution code:
N, M = list(map(int, input().split()))


drink_price = {}  # price -> size
for _ in range(N):
    A, B = list(map(int, input().split()))
    drink_price[A] = B

result = 0
num = 0
for price in sorted(drink_price):
    
    n = drink_price[price]
    num += n
    result += price * n
    if num >= M:
        result -= (num-M) * price
        break
print(result)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

N, M = map(int,input().split())
ABdic = dict()
for i in range(0,N):
    a,b = map(int,input().split())
    ABdic[a] = b

ans = 0
ABdic = sorted(ABdic.items(), key=lambda x:x[0])

for index, item in enumerate(ABdic):
    buy = 0
    if ABdic[index][1] > M:
        buy = M
    else:
        buy = ABdic[index][1]
    M -= buy
    ans += buy * ABdic[index][0]
    if M == 0:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,les=list(map(int,input().split()))
data=np.array([list(map(int,input().split())) for _ in range(N)])
cost=0

t=data[:,0]
for n in np.argsort(data[:,0]):
    if data[n][1]>les:
        cost+=les*data[n][0]
    else:
        les-=data[n][1]
        cost+=data[n][0]*data[n][1]
print(cost)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
sets = {}
costs_li=[]
bought=0
pay=0
for i in range (1,n+1):
    cost,limit=map(int,input().split())
    costs_li.append(cost)
    sets[str(cost)]=limit
costs_li.sort()
for j in range(0,n+1):
    if bought<m:
        pay=pay+costs_li[j]*sets[str(costs_li[j])]
        bought=bought+sets[str(costs_li[j])]
    elif bought>m:
        pay=pay-costs_li[j-1]*(bought-m)
        bought=m
    else:
        pay=pay
        bought=bought
print(pay)

Submission status: Wrong Answer

Solution code:
teisuu = input().split(" ")
N = int(teisuu[0])
M = int(teisuu[1])
ABlist = []
a = 0
ans = 0
z = 0
for i in range(N):
    ABlist.append(input().split(" "))
#print(ABlist)
sort_list = sorted(ABlist)
#print(sort_list)

for j in range(N):
    a += int(sort_list[j][1])
    b = j
    if a>M:
        break

for p in range(b):
    ans += int(sort_list[p][0])*int(sort_list[p][1])
    z += int(sort_list[p][1])

zan = M - z
ans += zan * int(sort_list[b][0])
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
sets = {}
costs_li=[]
bought=0
pay=0
for i in range (1,n+1):
    cost,limit=map(int,input().split())
    costs_li.append(cost)
    sets[str(cost)]=limit
costs_li.sort()
for j in range(0,n+1):
    if bought<m:
        pay=pay+costs_li[j]*sets[str(costs_li[j])]
        bought=bought+sets[str(costs_li[j])]
    elif bought>m:
        pay=pay-costs_li[j-1]*(bought-m)
        bought=m
    else:
        pay=pay
        bought=bought
print(pay)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
sets = {}
costs_li=[]
bought=0
pay=0
for i in range (1,n+1):
    cost,limit=map(int,input().split())
    costs_li.append(cost)
    sets[str(cost)]=limit
costs_li.sort()
for j in range(0,n+1):
    if bought<m:
        pay=pay+costs_li[j]*sets[str(costs_li[j])]
        bought=bought+sets[str(costs_li[j])]
    elif bought>m:
        pay=pay-costs_li[j-1]*(bought-m)
        bought=m
    else:
        pay=pay
        bought=bought
print(pay)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
sets = {}
costs_li=[]
limit_li=[]
bought=0
pay=0
for i in range (1,n+1):
    cost,limit=map(int,input().split())
    limit_li.append(cost)
    costs_li.append(cost)
    sets[str(cost)]=limit
costs_li.sort()
for j in range(0,n+1):
    if bought<m:
        pay=pay+costs_li[j]*sets[str(costs_li[j])]
        bought=bought+sets[str(costs_li[j])]
    elif bought>m:
        pay=pay-costs_li[j-1]*(bought-m)
        bought=m
    else:
        pay=pay
        bought=bought
print(pay)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
sets = {}
costs_li=[]
limit_li=[]
bought=0
pay=0
for i in range (1,n+1):
    cost,limit=map(int,input().split())
    limit_li.append(cost)
    costs_li.append(cost)
    sets[str(cost)]=limit
costs_li.sort()
for j in range(0,n+1):
    if bought<m:
        pay=pay+costs_li[j]*sets[str(costs_li[j])]
        bought=bought+sets[str(costs_li[j])]
    elif bought>m:
        pay=pay-costs_li[j-1]*(bought-m)
        bought=m
    else:
        pay=pay
        bought=bought
    print(pay)

Submission status: Wrong Answer

Solution code:
import numpy as np

def main():
    N, M = map(int, input().split())

    AB= np.array([list(map(int, list(input().split()))) for _ in range(N)])
    #print(AB)
    #AB = np.array([[4,9],[2,4]])
    AB_sort_by_A = np.sort(AB.view('i8,i8'), order=['f0'], axis=0).view(np.int)

    #print(AB_sort_by_A)
    buyNum = 0
    money = 0
    for i in range(N):
        if buyNum >= M:
            break
        else:
            drinkVal, drinkNum = AB_sort_by_A[i]
            if M - buyNum > drinkNum:
                buyNum += drinkNum
                money += drinkVal * drinkNum
            else:
                money += drinkVal * (M-buyNum)
    print(money)
        
            
    

    
    
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
sets = []
for _ in range(N):
    sets.append(list(map(int,input().split())))
    
def mergesort(sets):
    if len(sets) == 1:
        return [sets[0]]
    else:
        leng = len(sets)
        sets1 = mergesort(sets[:leng//2])
        sets2 = mergesort(sets[leng//2:])
        return merge(sets1,sets2)

def merge(set1,set2):
    i=0
    j=0
    result = []
    for _ in range(len(set1)+len(set2)):
        if i<len(set1) and j<len(set2):
            if set1[i][0] >= set2[j][0]:
                result.append(set2[j])
                j += 1
            elif set2[j][0] > set1[i][0]:
                result.append(set1[i])
                i += 1
        elif i == len(set1):
            result.append(set2[j])
            j += 1
        elif j == len(set2):
            result.append(set1[i])
            i += 1
    return result

def minimummoney(m,sets):
    sets = mergesort(sets)
    rest = m
    cost = 0
    for i in range(len(sets)):
        if rest > sets[i][1]:
            cost += sets[i][0]*sets[i][1]
            rest -= sets[i][1]
            continue
        if 0 < rest and rest < sets[i][1]:
            cost += rest * sets[i][0]
        break
    return cost

print(minimummoney(M,sets))

Submission status: Wrong Answer

Solution code:
N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(N)]

shop = {AB[i][0]:AB[i][1] for i in range(N)}
total = 0
kosuu = 0
while 1:
  key = min(shop.keys())
  for x in range(shop[key]):
    if kosuu < M:
      total += key
      kosuu += 1
    else:
      print(total)
      exit()

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
# N:売店数
# M:買う数
AB=[]
for i in range(N):
  ab=list(map(int,input().split()))
  AB.append(ab)
#AB[0]:A円，AB[1]:最大B本まで買える

list.sort(AB,key=lambda x:x[0])
#print(AB)

m=0 #買う数
cost=0 #かかる値段
for i in range(N):
 
 if M-m==AB[i][1]:
     m+=AB[i][1]
     cost+=AB[i][0]*AB[i][1]
     break

 elif M-m<AB[i][1] :
      for j in range(AB[i][1]+1):
         cost=cost+AB[i][0]*j
         m=m+j
         if m==M:
             break
         elif m<M:
             cost=cost-AB[i][0]*j
 else:
      cost+=AB[i][0]*AB[i][1]
      m+=AB[i][1]
    
print(cost)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
# N:売店数
# M:買う数
AB=[]
for i in range(N):
  ab=list(map(int,input().split()))
  AB.append(ab)
#AB[0]:A円，AB[1]:最大B本まで買える

list.sort(AB,key=lambda x:x[0])
#print(AB)

m=0 #買う数
cost=0 #かかる値段
for i in range(N):
 
 if M-m==AB[i][1]:
     m+=AB[i][1]
     cost+=AB[i][0]*AB[i][1]
     break

 elif M-m<AB[i][1] :
      for j in range(AB[i][1]+1):
         cost=cost+AB[i][0]*j
         m=m+j
         if m==M:
             break
         else:
             cost=cost-AB[i][0]*j
 else:
      cost+=AB[i][0]*AB[i][1]
      m+=AB[i][1]
    
print(cost)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
# N:売店数
# M:買う数
AB=[]
for i in range(N):
  ab=list(map(int,input().split()))
  AB.append(ab)
#AB[0]:A円，AB[1]:最大B本まで買える

list.sort(AB,key=lambda x:x[0])
#print(AB)

m=0 #買う数
cost=0 #かかる値段
for i in range(N):
 
 if M-m==AB[i][1]:
     m+=AB[i][1]
     cost+=AB[i][0]*AB[i][1]
     break

 elif M-m<AB[i][1] :
      for j in range(AB[i][1]+1):
         cost=cost+AB[i][0]*j
         m=m+j
         if m==M:
             break
 else:
      cost+=AB[i][0]*AB[i][1]
      m+=AB[i][1]
    
print(cost)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
# N:売店数
# M:買う数
AB=[]
for i in range(N):
  ab=list(map(int,input().split()))
  AB.append(ab)
#AB[0]:A円，AB[1]:最大B本まで買える

list.sort(AB,key=lambda x:x[0])
#print(AB)

m=0 #買う数
cost=0 #かかる値段
for i in range(N):
 cost+=AB[i][0]*AB[i][1]
 m+=AB[i][1]
 if m==M:
     break
 elif m>M:
     cost=cost-(AB[i][0]*AB[i][1])
     m=m-AB[i][1]
     for j in range(AB[i][1]+1):
         cost=cost+AB[i][0]*j
         m=m+j
         if m==M:
             break

print(cost)

Submission status: Wrong Answer

Solution code:
# -*- Coding: utf-8 -*-

import numpy as np

NM=list(map(int,input().split()))
AB=[0]*NM[0]
for i in range(NM[0]):
	AB[i]=list(map(int,input().split()))
AB=np.array(AB)

AB_sort=AB[np.argsort(AB[:,0])]
sum=0
count=0
print(AB_sort)
for i in range(NM[0]):
	for j in range(AB_sort[i,1]):
		if count==NM[1]:
			break
		sum=sum+AB_sort[i,0]
		count=count+1
		
print(sum)

Submission status: Wrong Answer

Solution code:
# -*- Coding: utf-8 -*-

import numpy as np

NM=list(map(int,input().split()))
AB=[0]*NM[0]
for i in range(NM[0]):
	AB[i]=list(map(int,input().split()))
AB=np.array(AB)

AB_sort=AB[np.argsort(AB[:,0])]
sum=0
count=0
print(AB_sort)
for i in range(NM[0]):
	for j in range(AB_sort[i,1]):
		sum=sum+AB_sort[i,0]
		count=count+1
		print(count)
		print(sum)
		if count==NM[1]:
			break
print(sum)

Submission status: Wrong Answer

Solution code:
from collections import OrderedDict
n, m = map(int, input().split())
A, B = [], []
D = OrderedDict()
for _ in range(n):
    ai, bi = map(int, input().split())
    D[ai] = bi
    
sorted_D = OrderedDict(sorted(D.items(), key=lambda x:x[0]))

#print(sorted_D)

bought = 0
cost = 0
for k, v in sorted_D.items():
    if bought == m:
        break
    for i in range(v):
        bought += 1
        cost += k
        #print(cost)
        if bought == m:
            break
    
            
print(cost)

Submission status: Wrong Answer

Solution code:
from collections import OrderedDict
n, m = map(int, input().split())
A, B = [], []
D = OrderedDict()
for _ in range(n):
    ai, bi = map(int, input().split())
    D[ai] = bi
    
sorted_D = OrderedDict(sorted(D.items(), key=lambda x:x[0]))

#print(sorted_D)

bought = 0
cost = 0
for k, v in sorted_D.items():
    for i in range(v):
        bought += 1
        cost += k
        #print(cost)
        if bought == m:
            break
    if bought == m:
        break
            
print(cost)

Submission status: Wrong Answer

Solution code:
N,M=map(int, input().split(" "))

A=[]
B=[]

bought = 0
price = 0
for i in range(0, N):
    a,b=list(map(int, input().split(" ")))
    A.append((a, i))
    B.append(b)

print(A)
A.sort()
print(B)

i = 0
p=0
n=0
while bought < M:
    p,n = A[i]
    price += p*B[n]
    bought += B[n]
    print("buy {} yen * {}".format(p, B[n]))
    i += 1

if bought > M:
    price -= (bought-M)*p

print(price)

Submission status: Wrong Answer

Solution code:
#coding: utf-8
import numpy as np

n, m = map(int, raw_input().split())
a = np.zeros((n, 2), dtype=np.uint64)
for i in np.arange(n):
    a[i] = np.array(map(int, raw_input().split()))

a = a[np.argsort(a[:,0])]

cost = 0L
for i in np.arange(n):
    if(a[i][1] < m):
        cost += a[i][0] * a[i][1]
        m -= a[i][1]
    else:
        cost += a[i][0] * m
        print(cost)
        exit()