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:
N, M = map(int,input().split())

AB = {}
for i in range(N):
  A, B = map(int,input().split())
  AB[A]=B
AB = sorted(AB.items(),key = lambda x:x[0])

cost = 0

for a,b in AB:
  cost += (min(max(M,0),b))*a
  M-=b
  if M<=0:
    break
print(cost)

Submission status: Wrong Answer

Solution code:
def main():
    N, M = map(int, input().split())
    a_b_dict = dict([tuple(map(int, input().split())) for _ in range(N)])
    ans = 0
    for a, b in sorted(a_b_dict.items()):
        if M >= b:
            M -= b
            ans += a * b
        else:
            ans += a * M
            break
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
stores = [tuple(map(int, input().split())) for _ in range(n)]
dict_stores = dict(stores)
sorted_dict = sorted(dict_stores.items(), key=lambda x: x[0])
total = 0
ans = 0
for cost, number in sorted_dict:
    total += number
    if total > m:
        diff = m - (total - number)
        ans += cost * diff
        break
    else:
        ans += cost * number
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
stores = [tuple(map(int, input().split())) for _ in range(n)]
dict_stores = dict(stores)
sorted_dict = sorted(dict_stores.items(), key=lambda x: x[0])
total = 0
ans = 0
for cost, number in sorted_dict:
    total += number
    if total >= m:
        diff = abs(m - (total - number))
        ans += cost * diff
        break
    else:
        ans += cost * number
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
stores = [tuple(map(int, input().split())) for _ in range(n)]
dict_stores = dict(stores)
sorted_dict = sorted(dict_stores.items(), key=lambda x: x[0])
total = 0
ans = 0
for cost, number in sorted_dict:
    total += number
    if total >= m:
        diff = m - (total - number)
        ans += cost * diff
        break
    else:
        ans += cost * number
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]

ab_sorted = sorted(ab, key=lambda x:(x[0], -x[1]))

num = 0
amount_of_money = 0
for i in range(n):
  buy = min(ab_sorted[i][1], m-num)
  num += buy
  amount_of_money += ab_sorted[i][0] * buy
    
  if num >= m:
    print(amount_of_money)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]

ab_sorted = sorted(ab, key=lambda x:(x[0], -x[1]))
print(ab_sorted)

num = 0
amount_of_money = 0
for i in range(n):
  buy = min(ab_sorted[i][1], m-num)
  num += buy
  amount_of_money += ab_sorted[i][0] * buy
    
  if num >= m:
    print(amount_of_money)

Submission status: Wrong Answer

Solution code:
N, M = list(map(int, input().split()))
L = [tuple(map(int, input().split())) for i in range(N)]
L.sort()
print(L)
ct = 0
cost = 0
i = 0
while ct < M:
    a = min(M-ct, L[i][1])
    ct += a
    cost += a*L[i][0]
    # print(ct,cost)
    i += 1
print(cost)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
sAB = sorted(AB, key=lambda x: x[0])

sB = [sAB[i][1] for i in range(N)]
cum_num = list(accumulate(sB))

num = 0
ans = 0
index_ = -1
for a, b in sAB:
    index_ += 1
    num += b
    if num >= M:
        break
    ans += a*b

ans += sAB[index_][0]*(M-cum_num[index_-1])

print(ans)

Submission status: Wrong Answer

Solution code:
n, m= map(int, input().split())
got=0
sell={}
buy=0
for i in range(n):
  a,b=map(int,input().split())
  if a not in sell:
    sell[a]=0
  sell[a]+=b
if n==1:
  print(m*a)
  exit()
sell=sorted(sell.items())
for lis in sell:
  got+=lis[1]
  if got>m:
    buy+=(m-got+lis[1])*lis[0]
    print(buy)
    exit()
  else:
    buy+=(lis[0])*(lis[1])

Submission status: Wrong Answer

Solution code:
n, m= map(int, input().split())
got=0
sell={}
buy=0
for i in range(n):
  a,b=map(int,input().split())
  if a not in sell:
    sell[a]=0
  sell[a]+=b
if n==1:
  print(m*b)
  exit()
sell=sorted(sell.items())
for lis in sell:
  got+=lis[1]
  if got>m:
    buy+=(m-got+lis[1])*lis[0]
    print(buy)
    exit()
  else:
    buy+=(lis[0])*(lis[1])

Submission status: Wrong Answer

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

j = 0
total = 0

for i in range(N):
  if (j + int(P[i][1])) < M:
    total += int(P[i][0]) * int(P[i][1])
    j += int(P[i][1])
  else:
    total += int(P[i][0]) * (M - j)
    break
print(total)

Submission status: Wrong Answer

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

Y = sorted(Y)
ans = 0
for i in range(N):
    if M >= Y[i][1]:
        ans += Y[i][0] * Y[i][1]
        M -= Y[i][1]

    else:
        ans += M * Y[i][0]
        print(int(ans))
        exit()

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
C = sorted(A)
cin = 0
ans = 0
while M > 0:
    if B[A.index(C[cin])] >= M:
        ans += C[cin]*M
        M = 0
    else:
        ans += C[cin] * B[A.index(C[cin])]
        M -= B[A.index(C[cin])]
        cin += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
dic={}
doll=0
for i in range(n):
  a,b=map(int,input().split())
  dic[a]=b
  
con=sorted(dic.items())

for k,v in con:
  if v<m:
    doll+=k*v
    m-=v
  else:
    doll+=k*m
    break
print(doll)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
dic={}
doll=0
for i in range(n):
  a,b=map(int,input().split())
  dic[a]=b
  
con=sorted(dic.items())

for k,v in con:
  if v<m:
    doll+=k*v
    m-=v
  else:
    doll+=k*m
    print(doll)
    exit()

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
dic={}
doll=0
for i in range(n):
  a,b=map(int,input().split())
  dic[a]=b
  
con=sorted(dic.items())
for k,v in con:
  if v<m:
    doll+=k*v
    m-=v
  else:
    doll+=k*m
    print(doll)
    exit()

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
A=[list(map(int,input().split())) for i in range(N)]
A=sorted(A,key=lambda x:x[0])
cost=0
num=0
for i in range(N):
    if num+A[i][1]>M:
        print(cost+A[i][0]*(M-num))
        break
    else:
        cost+=A[i][0]*A[i][1]
        num+=A[i][1]

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
A=[list(map(int,input().split())) for i in range(N)]
A=sorted(A,key=lambda x:x[1])
cost=0
num=0
for i in range(N):
    if num+A[i][1]>M:
        print(cost+A[i][0]*(M-num))
        break
    else:
        cost+=A[i][0]*A[i][1]
        num+=A[i][1]

Submission status: Wrong Answer

Solution code:
#a値段,b本数
n,m = list(map(int, input().split()))
a_lis =[]
b_lis = []
for _ in range(n):
    a,b = list(map(int, input().split()))
    a_lis.append(a)
    b_lis.append(b)
cp_lis = a_lis.copy()
cp_lis.sort()
ans = 0
num = 0

for i in cp_lis:
    ans += b_lis[a_lis.index(i)]*i
    num += b_lis[a_lis.index(i)]
    if num >= m:
        i_stop = cp_lis.index(i)
        break


     
diff_num = num - m
ans -= cp_lis[i_stop]*diff_num

print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
C = {}
for i in range(N):
    a, b = map(int,input().split())
    C[a] = b

sum = 0
price = 0

A = list(C.keys())
A.sort()

for i in range(len(A)):
    sum += C[A[i]]
    if sum >= M:
        sum -= C[A[i]]
        break
    price += A[i]*C[A[i]]

price += (M-sum)*A[i]

print(price)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab.sort()
num = 0
cnt = 0
hon = 0
if n == 1:
    print(m*ab[0][0])
    exit()
while num < m:
    num += ab[cnt][0]*ab[cnt][1]
    hon += ab[cnt][1]
    cnt += 1
rest = m - hon
print(num + rest*ab[cnt][0])

Submission status: Wrong Answer

Solution code:
n,m=list(map(int,input().split()))
d={}
for _ in range(n):
    a, b = list(map(int, input().split()))
    d[a]=b

sd=dict(sorted(d.items()))
result=0
ans=0
for i in sd:
	for j in range(sd[i]):
		ans+=i
		result+=1
		if result == m:
			print(ans)
			exit()

Submission status: Wrong Answer

Solution code:
n,m=list(map(int,input().split()))
d={}
for _ in range(n):
    a, b = list(map(int, input().split()))
    d[a]=b

sd=dict(sorted(d.items()))

result=0
ans=0
for i in sd:
	result+=d[i]
	ans+=i*d[i]
	if result>m:
		ans-=i*(result-m)
		break
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=list(map(int,input().split()))
d={}
for _ in range(n):
    a, b = list(map(int, input().split()))
    d[a]=b

sd=dict(sorted(d.items()))

result=0
ans=0
for i in sd:
	result+=d[i]
	ans+=i*d[i]
	if result>=m:
		ans-=i*(result-m)
		break
print(ans)

Submission status: Wrong Answer

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

C={}
S1=[]
for i in range(n):
    a,b = map(int,input().split())
    S1.append(a)
    if a in C:
        C[a]+=b
    else:
        C[a]=b
S=list(set(S1))

ans=0
os=0
for s in S:
    if os==s:
        continue
    
    # print(S,C,ans)
    if m<C[s] :
        ans+=m*s
        break
    else:
        ans+=C[s]*s
        m-=C[s]

print(ans)

Submission status: Wrong Answer

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

C={}
S=[]
for i in range(n):
    a,b = map(int,input().split())
    S.append(a)
    C[a]=b
S.sort()

ans=0
for s in S:
    # print(S,C,ans)
    if m<C[s] :
        ans+=m*s
        break
    else:
        ans+=C[s]*s
        m-=C[s]

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n, m = rm()
cnt = 0
cnt_money = 0
for i in sorted([rl() for _ in range(n)]):
  a, b = i
  if cnt + b < m:
    cnt += b
    cnt_money += a*b
  else:
    cnt_money += (m - cnt) * a
print(cnt_money)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
drink = {}
for _ in range(n):
    a,b = map(int,input().split())
    drink[a] = b
d = sorted(drink.items(), key=lambda x:x[0])

ans = 0
x = 0

for t in d:
    if x+t[1] < m:
        ans += t[0]*t[1]
        x += t[1]
    else:
        ans += (m-x)*t[0]
        break

print (ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
drink = {}
for _ in range(n):
    a,b = map(int,input().split())
    drink[a] = b

d = sorted(drink.items(), key=lambda x:x[0])

ans = 0
x = 0
for t in d:
    if m <= x+t[1]:
        ans += (m-x)*t[0]
        break
    else:
        ans += t[0]*t[1]
        x += t[1]

print (ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
Shop_List = [list(map(int,input().split())) for i in range(N)]
Shop_List = sorted(Shop_List, key=lambda x:x[0])
Number_Counter = 0
Yen_Counter = 0
for i in range(N):
    if Number_Counter + Shop_List[i][1] <= M:
        Number_Counter += Shop_List[i][1]
        Yen_Counter = Shop_List[i][0]*Shop_List[i][1]
    elif Number_Counter + Shop_List[i][1] > M:
        Yen_Counter += (M-Number_Counter)*Shop_List[i][0]
        Number_Counter = M
    elif Number_Counter == M:
        break

print(Yen_Counter)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
d = {}
for i in range(N):
    a, b = map(int, input().split())
    d[a] = b

d = sorted(d.items(), key=lambda x:x[0])
sum_ = 0
cnt = 0
for ab in d:
    if cnt + ab[1] > M:
        sum_ += ab[0] * (M-cnt)
        break
    else:
        cnt += ab[1]
        sum_ += ab[0]*ab[1]
print(sum_)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
d = {}
for i in range(N):
    a, b = map(int, input().split())
    d[a] = b

d = sorted(d.items(), key=lambda x:x[0])
sum_ = 0
cnt = 0
for ab in d:
    if cnt + ab[1] >= M:
        sum_ += ab[0] * (M-cnt)
        break
    else:
        cnt += ab[1]
        sum_ += ab[0]*ab[1]
print(sum_)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
d = {}
for i in range(N):
    a, b = map(int, input().split())
    d[a] = b

d = sorted(d.items(), key=lambda x:x[0])
sum_ = 0
cnt = 0
for ab in d:
    if cnt + ab[1] > M:
        for i in range(ab[1]):
            if cnt + 1 < M:
                cnt += 1
                sum_ += ab[0]

            elif cnt + 1 == M:
                sum_ += ab[0]
                break
        else:
            continue
        break
    else:
        cnt += ab[1]
        sum_ += ab[0]*ab[1]
print(sum_)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
C = {}
ans = 0
for _ in range(n):
    a, b = map(int, input().split())
    C[a] = b

for k, v in sorted(C.items()):
    t = min(m, v)
    ans += k*t
    m -= t

print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
C = {}
ans = 0
for _ in range(n):
    a, b = map(int, input().split())
    C[a] = b

for k, v in sorted(C.items()):
    if m > v:
        ans += k*v
        m -= v
    else:
        ans += k*m
        break

print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
C = {}
ans = 0
for _ in range(n):
    a, b = map(int, input().split())
    C[a] = b

for k, v in sorted(C.items()):
    if m > v:
        ans += k*v
        m -= v
    else:
        ans += k*m
        print(ans)
        exit()

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
list = []
for i in range(n) :
    a, b = map(int, input().split())
    list.append([a, b])
list.sort(key=lambda x:x[0])
count = 0 ; ans = 0
for i in range(n) :
    if list[i][1] < m - count :
        ans += list[i][0] * list[i][1]
        count += list[i][1]
    elif list[i][1] > m - count :
        ans += list[i][0] * (m - count)
        break
print(ans)

Submission status: Wrong Answer

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

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

dic_2 = sorted(dic_1.items())

cost = 0
cnt = 0
flg = False
for key, value in dic_2:
    for i in range(value):
        cost += key
        cnt += 1
        
        if cnt == M:
            flg = True
            break
    
    if flg:
        break

print(cost)

Submission status: Wrong Answer

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

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

dic_2 = sorted(dic_1.items())

cost = 0
cost_prev = 0
cnt = 0
cnt_prev = 0
flg = False
for key, value in dic_2:
    if flg:
        break
    cost += key*value
    cnt += value

    if cnt >= M:
        dif = M-cnt_prev
        cost_prev += key*dif
        flg = True

    if flg == False:
        cost_prev = cost
        cnt_prev = cnt

print(cost_prev)

Submission status: Wrong Answer

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

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

dic_2 = sorted(dic_1.items())

cost = 0
cost_prev = 0
cnt = 0
cnt_prev = 0
flg = False
for key, value in dic_2:
    if flg:
        break
    cost += key*value
    cnt += value

    if cnt > M:
        for i in range(value):
            cnt_prev += 1
            cost_prev += key
            if cnt_prev == M:
                flg = True
                break
    elif cnt == M:
        cost_prev = cost
        cnt_prev = cnt
        flg = True        

    if flg == False:
        cost_prev = cost
        cnt_prev = cnt

print(cost_prev)

Submission status: Wrong Answer

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

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

dic_2 = sorted(dic_1.items())

cost = 0
cost_prev = 0
cnt = 0
cnt_prev = 0
flg = False
for key, value in dic_2:
    if flg:
        break
    cost += key*value
    cnt += value

    if cnt > M:
        for i in range(value):
            cnt_prev += 1
            cost_prev += key
            if cnt_prev == M:
                flg = True
                break
    elif cost == M:
        cost_prev = cost
        cnt_prev = cnt
        flg = True        

    if flg == False:
        cost_prev = cost
        cnt_prev = cnt

print(cost_prev)

Submission status: Wrong Answer

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

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

dic_2 = sorted(dic_1.items())

cost = 0
cost_prev = 0
cnt = 0
cnt_prev = 0
flg = False
for key, value in dic_2:
    if flg:
        break
    cost += key*value
    cnt += value

    if cnt >= M:
        for i in range(value):
            cnt_prev += 1
            cost_prev += key
            if cnt_prev == M:
                flg = True
                break

    if flg == False:
        cost_prev = cost
        cnt_prev = cnt

print(cost_prev)

Submission status: Wrong Answer

Solution code:
import numpy as np

N,M=map(int,input().split())
l=[]
for n in range(N):
    A,B=map(int,input().split())
    temp_l=[A,B]
    l.append(temp_l)
arr=np.array(l,dtype=np.int64)
# print(l)
# print(arr)

need=M
ans=0


col_num=0
# route=np.sort(arr,axis=0)  #numpyソートの仕方がおかしい
route=arr[np.argsort(arr[:,col_num])]
print(route)
for i in range(N):
    if need >= route[i,1]:
        ans+=route[i,0]*route[i,1]
        need-=route[i,1]
        if need==0:
            break
        else:
            continue
    else:
        ans+=route[i,0]*need
        need=0
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

def solve():
    cnt = 0
    money = 0
    for i in range(N):
        if cnt >= M:
            break
        if cnt + AB[i][1] >= M:
            money += AB[i][0] * (M - cnt)
            cnt = M   
        else:
            money += AB[i][0]*AB[i][1]
            cnt = AB[i][1]
#    print(cnt)
    print(money)

if __name__ == "__main__":
    N,M = list(map(int, input().split()))   
    AB = [list(map(int, input().split())) for _ in range(N)]
    AB.sort(key=lambda x: x[0])
#    print(AB)
    solve()

Submission status: Wrong Answer

Solution code:
import numpy as np

def solve():
    cnt = 0
    money = 0
    for i in range(N):
        if cnt >= M:
            break
        if cnt + AB[i][1] >= M:
            money += AB[i][0] * (M - cnt)
            cnt = M   
        else:
            money += AB[i][0]*AB[i][1]
            cnt = AB[i][1]
    print(cnt)
    print(money)

if __name__ == "__main__":
    N,M = list(map(int, input().split()))   
    AB = [list(map(int, input().split())) for _ in range(N)]
    AB.sort(key=lambda x: x[0])
#    print(AB)
    solve()

Submission status: Wrong Answer

Solution code:
import numpy as np

def solve():
    cnt = 0
    money = 0
#    dp = np.zeros((N+1, M+1))
    for i in range(N):
        if cnt + AB[i][1] < M:
            cnt += AB[i][1]
            money += AB[i][0]*AB[i][1]
        else:  
            j = 1
            while j < AB[i][1]:
                if cnt < M:
                    cnt += 1
                    money += AB[i][0]
                    j += 1
                else:
                    break
#    print(cnt)
    print(money)

if __name__ == "__main__":
    N,M = list(map(int, input().split()))   
    AB = [list(map(int, input().split())) for _ in range(N)]
    AB.sort(key=lambda x: x[0])
#    print(AB)
    solve()

Submission status: Wrong Answer

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

AB = sorted(AB)
total=0
for i in range(N):
    if AB[i][1]>M:
        total = total + AB[i][0]*M
    else:
        total = total + AB[i][0]*AB[i][1]
        M = M - AB[i][1]
print(total)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
shop={}
for i in range(N):
    A,B=map(int,input().split())
    shop[A]=B


shop1=sorted(shop.items())

count=0
ans=0
for (key,value) in shop1:
    if M-count==value:
        break
    elif M-count<value:
        ans+= (M-count)*key
        break
    else:
        ans+=value*key
        count+=value
    
print(ans)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
shop={}
for i in range(N):
    A,B=map(int,input().split())
    shop[A]=B

shop1=sorted(shop.items())
count=0
ans=0
for (key,value) in shop1:
    if M-count<=value:
        ans+= (M-count)*key
        break
    else:
        ans+=value*key
        count+=value
    
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
from itertools import accumulate

N, M = map(int, input().split())
shop = [list(map(int, input().split())) for _ in range(N)]
shop.sort(key=lambda x: x[0])

money_sum = (list(accumulate([i[0] * i[1] for i in shop])))
drink_sum = (list(accumulate([i[1] for i in shop])))

drink = 0
money = 0

idx = bisect_left(drink_sum, M)

drink = drink_sum[idx - 1]
money = money_sum[idx - 1]

for _ in range(shop[idx][1]):
    if drink == M:
        break
    else:
        drink += 1
        money += shop[idx][0]

print(money)

Submission status: Wrong Answer

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

info.sort(key=lambda x:x[1])
ans=0
for a, b in info:
  if M>=b:
    ans+=a*b
    M-=b
  elif M<b and M>0:
    ans+=a*M
    break
  else:
    break
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
drink=[list(map(int,input().split())) for i in range(n)]
#print(drink)

drink.sort()
#print(drink)
money=0
number=0
for i in range(n):
    if number+drink[i][0]<=m:
        money+=drink[i][0]*drink[i][1]
        number+=drink[i][1]
    elif m<number+drink[i][0]:
        money+=drink[i][0]*(m-number)
        number+=m-number
        break
    if m==number:
        break
print(money)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
drink=[list(map(int,input().split())) for i in range(n)]
#print(drink)

drink.sort()
#print(drink)
money=0
number=0
for i in range(n):
    if number+drink[i][0]<m:
        money+=drink[i][0]*drink[i][1]
        number+=drink[i][1]
    elif m<number+drink[i][0]:
        money+=drink[i][0]*(m-number)
        number+=m-number
        break
    if m==number:
        break
print(money)

Submission status: Wrong Answer

Solution code:

import collections
n,m = map(int,raw_input().split(' '))

costs = [map(int, raw_input().split(' ')) for _ in range(n)]
costs.sort(key = lambda x:-x[0])
q = collections.deque(costs)
r = 0
while(m):
	u,v = q.popleft()
	t = min(v,m)
	m -=t
	r += t * u
print r

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline


def main():
    N, M = map(int, readline().split())
    AB = np.array(read().split(), np.int32).reshape((N, 2))
    AB = AB[np.argsort(AB[:, 0])]

    m = M
    ans = 0
    for i in range(N):
        if AB[i][1] < m:
            ans += AB[i][0] * AB[i][1]
            m -= AB[i][1]
        else:
            ans += AB[i][0] * m
            break

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

a=sorted([list(map(int,input().split())) for _ in range(n)])

print(a)
pay=0
i=0
while m>0:
    p=min(m,a[i][1])
    m-=p
    pay+=p*a[i][0]
    i+=1
print(pay)

Submission status: Wrong Answer

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

ans = 0
for ab in sorted(AB.keys()):
  if M >= AB[ab]:
    ans += ab * AB[ab]
    M -= AB[ab]
  else:
    ans += ab * M
    M = 0
  if M <= 0:
    break

print(ans)

Submission status: Wrong Answer

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

ans = 0
for ab in sorted(AB.keys()):
  if M <= 0:
    break
  if M >= AB[ab]:
    ans += ab * AB[ab]
    M -= AB[ab]
  else:
    ans += ab * M
    M = 0
print(ans)

Submission status: Wrong Answer

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

ans = 0
for ab in sorted(AB.keys()):
  if M < 0:
    break
  if M >= AB[ab]:
    ans += ab * AB[ab]
    M -= AB[ab]
  else:
    ans += ab * M
    M = 0
print(ans)

Submission status: Wrong Answer

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

ans = 0
for ab in sorted(AB.keys()):
  if M >= AB[ab]:
    ans += ab * AB[ab]
    M -= AB[ab]
  else:
    ans += ab * M
    break
print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
AB = {}
for i in range(N):
  a, b = map(int, input().split())
  AB[a] = b
ans = 0
for ab in AB:
  if M >= AB[ab]:
    ans += ab * AB[ab]
    M -= AB[ab]
  else:
    ans += ab * M
    break
print(ans)

Submission status: Wrong Answer

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

s_A = sorted(A)

cost = 0
bought = 0
for n in range(N):
  for _ in range(s_A[n][1]):
    cost += s_A[n][0]
    bought += 1
    if bought == M:
      break
print(cost)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
A = []
B = []
count = M
ans = 0
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
C = sorted(A)

for i in range(N):
    min_a = C[0]
    min_index = A.index(min_a)
    min_B = B[min_index]
    if count <= 0:
        break
    if min_B <= count:
        ans += min_B*min_a
        count -= min_B
    else:
        ans += min_a*count
        count = 0
    C.pop(0)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n,m = map(int,input().split())
d = dict()

for _ in range(n):
    a,b = map(int,input().split())
    d[a] = b

d = sorted(d.items())

ans = 0

c = m
for i in range(len(d)):
    if d[i][1] >= c:
        ans += c*d[i][0]
        print(ans)
        sys.exit()
    else:
        ans += d[i][0]*d[i][1]
        c -= d[i][1]

Submission status: Wrong Answer

Solution code:
import sys
n,m = map(int,input().split())
d = dict()

for _ in range(n):
    a,b = map(int,input().split())
    d[a] = b

d = sorted(d.items())

ans = 0

for i in range(len(d)):
    if d[i][1] >= m:
        ans += m*d[i][0]
        print(ans)
        sys.exit()
    else:
        ans += d[i][0]*d[i][1]
        m -= d[i][1]

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
d = {}
for i in range(n):
    a,b = map(int,input().split())
    d[a] = b

d_sorted = sorted(d.items(),key=lambda x:x[0])
price = 0
c = m

while c > 0:
    for i in range(len(d_sorted)):
        l = list(d_sorted[i])
        if d_sorted[i][1] > c:
            price += d_sorted[i][0]*c
            c = 0
        else:
            price += d_sorted[i][0]*d_sorted[i][1]
            c -= d_sorted[i][1]

print(price)

Submission status: Wrong Answer

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

vdic = {}

for i in range(N):
  if A[i] not in vdic.keys():
    vdic[A[i]] = B[i]
  else:
    vdic[A[i]] += B[i]
    
count = 0
cost = 0
    
for i in vdic.keys():
  if vdic[i] + count >= M:
    cost += (M - count) * i
    break
  else:
    cost += vdic[i] * i
    count += vdic[i]
    
print(cost)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc121/tasks/abc121_c

n, m = map(int, input().split())

shop = []
for _ in range(n):
    a, b = map(int, input().split())
    shop.append((a, b))

shop.sort(key=lambda x: x[1])

c = 0
ans = 0
i = 0
while c < m and i < n:
    a, b = shop[i]
    if c + b >= m:
        ans += (m - c) * a
        c += (m - c)
    else:
        ans += b * a
        c += b
    i += 1
print(ans)

Submission status: Wrong Answer

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

store_list = {}
for _ in range(N):
  A, B = map(int, input().split())
  store_list[A] = B
  
store_list = sorted(store_list.items(), key=lambda x:x[0])

ans = 0
for A,B in store_list:
  num = min(M, B)
  ans += A * num
  M -= num
  if M == 0:
    break

print(ans)

Submission status: Wrong Answer

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

ans = 0
for i in range(N):
  #まだ足りないケース
  if M > AB[i][1]:
    ans += AB[i][0] * AB[i][1]
    M -= AB[i][1]
  else:
    ans += AB[i][0] * M
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n,m=map(int,input().split())
d=defaultdict()
for _ in range(n):
    a,b=map(int,input().split())
    d[a]=+b
def c(dic):
    s=0
    cost=0
    d2=sorted(d.keys())
    for i in range(len(d2)):
        for _ in range(d[d2[i]]):
            cost+=d2[i]
            s+=1
            if s==m:
                return cost
print(c(d))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
d={}
for _ in range(n):
    a,b=map(int,input().split())
    d[a]=b
def c(dic):
    s=0
    cost=0
    for x in sorted(d.keys()):
        for _ in range(d[x]):
            cost+=x
            s+=1
            if s==m:
                return cost
print(c(d))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
d={}
for _ in range(n):
    a,b=map(int,input().split())
    d[a]=b
d2 = dict(sorted(d.items()))
def c(dic):
    s=0
    cost=0
    for x in d2.keys():
        for _ in range(d2[x]):
            cost+=x
            s+=1
            if s==m:
                return cost
print(c(d2))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
AB = []
for _ in range(N):
    AB.append([int(i) for i in input().split()])
AB_sort = sorted(AB,key=lambda x : x[0])
money = 0
for ab in AB_sort:
    if M >= ab[0]:
        money += ab[0] * ab[1]
        M -= ab[1]
    else:
        money += M * ab[0]
        break
print(money)