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 = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x:x[0])

ans = 0
for i in range(n):
    print(ab[i][1], m)
    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)

Submission status: Wrong Answer

Solution code:
import heapq

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

heapq.heapify(L)
# heapq.heapify(sorted(L, key=lambda x: x[0]))
print(L)
drink = 0
yen = 0
while drink < M:
    a, b = heapq.heappop(L)
    if drink + b <= M:
        yen += a * b
        drink += b
    else:
        yen += a * (M - drink)
        break
print(yen)

Submission status: Wrong Answer

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

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

ans = 0
for ai, bi in sorted(drink.items(), key=lambda x:x[0]):
  ans += ai * min(drink[ai], m)
  m -= drink[ai]
  if m <= 0:
    print(ans)
    break

Submission status: Wrong Answer

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

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

ans = 0
for ai, bi in sorted(drink.items(), key=lambda x:x[0]):
  ans += ai * min(drink[ai], m)
  m -= min(drink[ai], m)
  if m <= 0:
    break
print(ans)

Submission status: Wrong Answer

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

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

ans = 0
for ai, bi in sorted(drink.items(), key=lambda x:x[0]):
  ans += ai * min(drink[ai], m)
  m -= drink[ai]
  if m < 0:
    break
print(ans)

Submission status: Wrong Answer

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

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

ans = 0
for ai, bi in sorted(drink.items(), key=lambda x:x[0]):
  ans += ai * min(drink[ai], m)
  m -= drink[ai]
  if m <= 0:
    break
print(ans)

Submission status: Wrong Answer

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

S.sort(key=lambda x: x[0])
price = 0
count = 0
for s in S:
  if count + s[1] < M:
    price += s[0] * s[1]
    count += s[1]
  else:
    price += s[0] * (M - s[1])
    break

print(price)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
array=[]
cost=0
for i in range(n):
    a,b=map(int,input().split())
    array.append([a,b])
array.sort()
for i in array:
    if m<=i[1]:
        cost+=i[0]*m
    else:
        cost+=i[0]*i[1]
        m-=i[1]
        
print(cost)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
array=[]
cost=0
for i in range(n):
    a,b=map(int,input().split())
    array.append([a,b])
array.sort()
for i in array:
    if m<i[1]:
        cost+=i[0]*m
    else:
        cost+=i[0]*i[1]
        m-=i[1]
        
print(cost)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

S.sort(key=lambda x: x[0])
ans = 0
for s in S:
  if ans + s[0] * s[1] < M:
    ans += s[0] * s[1]
  else:
    q = (M - ans + s[0] - 1) // s[0]
    ans += s[0] * q
    break

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
drink = dict()
cost = set()
ans = 0
for i in range(n):
    ab = [int(i) for i in input().split()]
    cost.add(ab[0])
    if ab[0] in drink:
        drink[ab[0]] += ab[1]
    else:
        drink[ab[0]] = ab[1]
#ここまで入力
sorted(cost)
for i in cost:
    if m <= drink[i]:
        ans += m*i
        break
    else:
        m -= drink[i]
        ans += i * drink[i] 
    
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
li = []
for i in range(n):
    a,b = map(int,input().split())
    li.append([str(a),b])
li = sorted(li)
coin = 0
cnt = 0
i = 0
while cnt != m:
    if li[i][1]>0:
        cnt+=1
        coin += int(li[i][0])
        li[i][1]-=1
    else:
        i+=1
print(coin)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
drink = dict()
cost = []
ans = 0
for i in range(n):
    ab = [int(i) for i in input().split()]
    cost.append(ab[0])
    if ab[0] in drink:
        drink[ab[0]] += ab[1]
    else:
        drink[ab[0]] = ab[1]
#ここまで入力
cost.sort()
for i in cost:
    if m <= drink[i]:
        ans += m*i
        break
    else:
        m -= drink[i]
        ans += i * drink[i] 
    
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
li = []
for i in range(n):
    a,b = map(int,input().split())
    li.append([str(a),b])
li = sorted(li)
coin = 0
cnt = 0
i = 0
while cnt != m:
    if li[i][1] <= 0:
        i+=1
    else:
        li[i][1]-=1
        coin += int(li[i][0])
        cnt +=1
print(coin)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
drink = dict()
cost = []
ans = 0
for i in range(n):
    ab = [int(i) for i in input().split()]
    cost.append(ab[0])
    if ab[0] in drink:
        drink[ab[0]] = drink[ab[0]] + ab[1]
    else:
        drink[ab[0]] = ab[1]
#ここまで入力
cost.sort()
for i in cost:
    if m <= drink[i]:
        ans += m*i
        break
    else:
        m -= drink[i]
        ans += i * drink[i] 
    
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
drink = dict()
cost = []
ans = 0
for i in range(n):
    ab = [int(i) for i in input().split()]
    cost.append(ab[0])
    drink[ab[0]] = ab[1]
#ここまで入力
cost.sort()
for i in cost:
    if m <= drink[i]:
        ans += m*i
        break
    else:
        m -= drink[i]
        ans += i * drink[i] 
    
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
drink = dict()
cost = []
ans = 0
for i in range(n):
    ab = [int(i) for i in input().split()]
    cost.append(ab[0])
    drink[ab[0]] = ab[1]
#ここまで入力
cost.sort()
for i in cost:
    if m < drink[i]:
        ans += m*i
        break
    else:
        m -= drink[i]
        ans += i * drink[i] 
    
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

N,M =[int(i) for i in input().split()]

AB = np.ones([N,2])


for i in range(N):
    AB[i,0],AB[i,1] = [int(i) for i in input().split()]
    
count=0
price=0

AB_new = np.sort(AB,axis=0)

for i in range(N):
    if count<=M:
        count+=AB_new[i,1]
        if count<=M:
            price+=AB_new[i,0]*AB_new[i,1]
        if count>M:
            price+=AB_new[i,0]*(M-count+AB_new[i,1])
    else:
        break

        
print(int(price))

Submission status: Wrong Answer

Solution code:
import numpy as np

N,M =[int(i) for i in input().split()]

A = np.ones(N)
B = np.ones(N)

for i in range(N):
    A[i],B[i] = [int(i) for i in input().split()]
    
count=0
price=0
for i in range(N):
    if count>=M:
        break
    min_pr = min(A)
    min_num = np.where(A==min_pr)
    min_num_count = 0
    for i in min_num[0]:
        min_num_count +=B[i]
    if (count+min_num_count) <=M:
        price+=min_num_count*min_pr
        count+=min_num_count
    elif (count+min_num_count) >M:
        price += (M-count)*min_pr
        count+=min_num_count
    A = A[A>min_pr]
        
print(int(price))

Submission status: Wrong Answer

Solution code:
N ,M = (map(int , input().split()))
e_dict = {}
for i in range(N):
    A ,B = (map(int , input().split()))
    e_dict[A] = B
e_sorted = sorted(e_dict.items(), key=lambda x:x[0])
drink = 0
cost = 0
for a in e_sorted:
    drink += a[1]
    cost += a[0] * a[1]
    if drink >= M:
        break
sabun = drink - M
ans = cost - (sabun * a[0])
print(ans)

Submission status: Wrong Answer

Solution code:
N ,M = (map(int , input().split()))
e_dict = {}
for i in range(N):
    A ,B = (map(int , input().split()))
    e_dict[A] = B
e_dict_sorted = dict(sorted(e_dict.items(), key=lambda x:x[0]))
drink = 0
cost = 0
for s_cost , s_drink in e_dict_sorted.items():
    drink += s_drink
    cost += s_cost * s_drink
    if drink >= M:
        break
sabun = drink - M
ans = cost - (sabun * s_cost)
print(ans)

Submission status: Wrong Answer

Solution code:
N ,M = (map(int , input().split()))
e_dict = {}
for i in range(N):
    A ,B = (map(int , input().split()))
    e_dict[A] = B
e_dict_sorted = dict(sorted(e_dict.items(), key=lambda x:x[0]))
honsuu = 0
kane = 0
for k , v in e_dict_sorted.items():
    honsuu += v
    kane += k * v
    if honsuu >= M:
        break
hiku = honsuu - M
ans = kane - (hiku*k)
print(ans)

Submission status: Wrong Answer

Solution code:
N ,M = (map(int , input().split()))
e_dict = {}
for i in range(N):
    A ,B = (map(int , input().split()))
    e_dict[A] = B
e_dict_sorted = sorted(e_dict.items(), key=lambda x:x[0])
honsuu = 0
kane = 0
for i in e_dict_sorted:
    honsuu += i[1]
    kane += i[0]*i[1]
    if honsuu >= M:
        break
hiku = honsuu - M
ans = kane - (hiku*i[0])
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()
count = 0
ans = 0
for i,j in AB:
  if count+j >= M:
    ans += (M-count)*i
    break
  else:
    count += j
    ans += j*i
  print(ans)

Submission status: Wrong Answer

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


p=0
v=m
for i in range(n):
	if l[i][1]<=v:
		p+=l[i][0]*l[i][1]
		v=v-l[i][1]
	else:
		p+=v*l[i][0]
		print(p)
		exit()

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N, M = map(int, input().split())
AB = sorted([list(map(int, input().split())) for i in range(N)], key=itemgetter(0))
ans, tmp = 0, 0
print(AB)
for ab in AB:
    if ab[1] + tmp < M:
        tmp += ab[1]
        ans += ab[0] * ab[1]
        print(tmp, ans)
    else:
        ans += (M - tmp) * ab[0]
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N_ken, M_hon = map(int, input().split())
ab = []
yen = 0
hon = 0

for i in range(N_ken):
    tmp = list(map(int, input().split()))
    ab.append(tmp)

ab.sort()

for a, b in ab:
    tmp = min(M_hon - hon, b)
    yen += tmp * a
    hon += b
    
    
    if (hon == M_hon):
        break

print(yen)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=[]
b=[]
ai,bi=map(int,input().split())
a.append(ai)
b.append(bi)
for i in range(1,n):
    ai,bi=map(int,input().split())
    for ii in range(i-1):
        if ai<a[ii]:
            a.insert(ii,ai)
            b.insert(ii,bi)
            break
    if len(a)== i:
        a.append(ai)
        b.append(bi)
#print(a)
#print(b)
msum=0
asum=0
for i in range(n):
    asum=asum+a[i]*b[i]
    msum=msum+b[i]  
    if msum>=m:
        break
asum=asum-a[i]*(msum-m)
print(asum)
#print(i,msum,m)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

C = Counter({a:b for a, b in AB})
print(sum(sorted(C.elements())[:M]))

Submission status: Wrong Answer

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

ans = 0
cnt = 0
for a, b in AB:
  if cnt+b <= M:
    cnt += b
    ans += a*b
    continue
  ans += a * (M - cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
ll = sorted(l)
count, total, i = 0, 0, 0
while count < m:
    count += ll[i][1]
    total += ll[i][0]*ll[i][1]
    i += 1
if i == n:
    total += ll[i-1][0]*(m-count)
    print(total)
    exit()
total += ll[i][0]*(m-count)
print(total)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=[0]*n
b=[0]*n
for i in range(n):
    a[i],b[i]=map(int,input().split())
pay=0
drink=0
for i in range(n):
    index=b.index(min(b))
    A=a.pop(index)
    B=b.pop(index)
    drink+=B
    pay+=A*B
    if drink>=m:
        break
if drink==m:
    print(pay)
else:
    dif=drink-m
    print(pay-dif*A)

Submission status: Wrong Answer

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

li.sort()
n = 0
ans = 0
for i in range(n):
    a = min(m,li[i][1])
    m-=a
    ans += li[i][0]*a
    if a ==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)]


from operator import itemgetter
def main():
    AB.sort(key = itemgetter(0))
    cnt = 0
    ans = 0
    for a,b in AB:
        if b + cnt < m:
            cnt += b 
            ans += b*a
        else:
            ans += (m - cnt)*a
    print(ans)
    return



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,m=map(int,readline().split())
d = map(int,read().split())
data = list(zip(d,d))
data.sort(key=lambda x:x[0])
c=0
for x,y in data:
  if m-c<=y:
    c+=m-c
    break
  else:
    c+=y
print(c)

Submission status: Wrong Answer

Solution code:
N,M=map(int, input().split())  
A = [0] * N
B = [0] * N

for i in range(N):
    A[i],B[i] = map(int, input().split())  

C = dict(zip(A,B))

c_sorted = sorted(C.items(), key=lambda x:x[0])

ans = 0
cnt = 0

for k,v in dict(c_sorted).items():
    if (cnt + v< M):
        ans += k*v
    else:
        ans += (M-cnt) * k
        break
    cnt += v
print(ans)

Submission status: Wrong Answer

Solution code:
N,M=map(int, input().split())  
A = [0] * N
B = [0] * N

for i in range(N):
    A[i],B[i] = map(int, input().split())  

C = dict(zip(A,B))

c_sorted = sorted(C.items(), key=lambda x:x[0])

ans = 0
cnt = 0

for k,v in dict(c_sorted).items():
    cnt += v
    if (cnt < M):
        ans += k*v
    else:
        ans += (M-cnt+v) * k
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N,M=map(int, input().split())  
A = [0] * N
B = [0] * N

for i in range(N):
    A[i],B[i] = map(int, input().split())  

C = dict(zip(A,B))

c_sorted = sorted(C.items(), key=lambda x:x[0])

ans = 0
cnt = 0

for k,v in dict(c_sorted).items():
    cnt += v
    if (cnt <= M):
        ans += k*v
    else:
        ans += (M-cnt+v) * k
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
a = []
b = []
for i in range(n):
    P,Y = map(int,input().split())
    a.append(P)
    b.append(Y)
#ここまで情報のインプット

#基本方針はまだ扱っていない最小のお金を持つ栄養ドリンクをとっていく。
#つまりは値がちいさいものから順に在庫が切れるまで選択するということ。

count = 0
ans = 0
i = 0
A = sorted(a)
if n-m < n//2:
    while i < n:
        if m-b[a.index(A[i])] > 0:
            m -= b[a.index(A[i])]
            ans += A[i] * b[a.index(A[i])]
        else:
            ans += A[i]* m
            break
        i+=1
else:
    while i < n:
        if m-b[a.index(A[(i+1)*(-1)])] > 0:
            m -= b[a.index(A[(i+1)*(i-1)])]
            ans += A[(i+1)*(-1)] * b[a.index(A[(i+1)*(-1)])]
        else:
            ans += A[(i+1)*(-1)] * m
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
a = []
b = []
for i in range(n):
    P,Y = map(int,input().split())
    a.append(P)
    b.append(Y)
#ここまで情報のインプット

#基本方針はまだ扱っていない最小のお金を持つ栄養ドリンクをとっていく。
#つまりは値がちいさいものから順に在庫が切れるまで選択するということ。

count = 0
ans = 0
i = 0
A = sorted(a)
while i < n:
    if m-b[a.index(A[i])] > 0:
        m -= b[a.index(A[i])]
        ans += A[i] * b[a.index(A[i])]
    else:
        ans += A[i]* m
        break
    i+=1
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()
print(AB)
cnt=0
i=-1
ans=0
while cnt<m:
    i+=1
    ans+=AB[i][0]*AB[i][1]
    cnt+=AB[i][1]
    #print(ans,cnt)
ans-=AB[i][0]*AB[i][1]
cnt-=AB[i][1]
#print(ans,cnt)
while cnt<m:
    ans+=AB[i][0]
    cnt+=1
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.sort()
ans = 0
for i in range(10*9):
    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)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
k=[list(map(int,input().split())) for i in range(n)]
dict={}
cnt=0
for i in k:
  dict[i[0]]=i[1]
dict=sorted(dict.items())
for i in dict:
  if(m-i[1]>0):
    m=m-i[1]
    cnt+=(i[0]*i[1])
  else:
    cnt+=(i[0]*m)
    break
print(cnt)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
k=[list(map(int,input().split())) for i in range(n)]
dict={}
cnt=0
for i in k:
  dict[i[0]]=i[1]
print(dict)
dict=sorted(dict.items())
print(dict)
for i in dict:
  if(m-i[1]>0):
    m=m-i[1]
    cnt+=(i[0]*i[1])
  else:
    cnt+=(i[0]*m)
    break
print(cnt)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
a.sort()
dr=0
i=0
pr=0
while(dr<m):
  if dr+a[i][1]>=m:
    dr+=m-dr
    pr+=(m-dr)*a[i][0]
  else:
    dr+=a[i][1]
    pr+=a[i][0]*a[i][1]
  i+=1
print(pr)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N,M = map(int,input().split())
ls = [list(map(int,input().split())) for _ in range(N)]
ls = sorted(ls,key=itemgetter(0))
ans = 0
pon = 0
for i in range(N):
    if pon < M:
        pon += ls[i][1]
        ans += ls[i][1]*ls[i][0]
    else:
        break
if pon == M:
    print(ans)
else:
    ans -= ls[i-1][0]*(pon - M)
    print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
store = [list(map(int, input().split())) for i in range(N)]
store = sorted(store, key=lambda x: x[0])

ans = 0
cnt = 0
for i in range(N):
    if cnt == M:
        print(ans)
        exit()

    else:
        if abs(cnt-M) >= store[i][1]:
            ans += store[i][0] * store[i][1]
            cnt += store[i][1]

        else:
            ans += store[i][0] * abs(cnt-M)
            cnt += store[i][1] - (store[i][1] - cnt)

print(ans)

Submission status: Wrong Answer

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

for x in a:
  dic[x[0]] = x[1]

sorted_dict = sorted(dic.items(), key=lambda x:x[0])

count = 0
for x in sorted_dict:
  if count < m:
    lis += [x[0]] * x[1]
    count += x[1]
  else:
    break
  
#print(lis)
print(sum(lis[:m]))

Submission status: Wrong Answer

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

for x in a:
  dic[x[0]] = x[1]

sorted_dict = sorted(dic.items(), key=lambda x:x[0])

for x in sorted_dict:
  lis += [x[0]] * x[1]
  
print(sum(lis[: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, key=lambda x: x[0])
ans=0
i=0
for a, b in sorted_ab:
  for _ in range(b):
    if i < m:
      ans+=a
      i+=1
    else:
      break

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, key=lambda x: x[0])
ans=0
i=0
for a, b in sorted_ab:
  for _ in range(b):
    if i < m:
      ans+=a
      i+=1
    else:
      print(ans)
      exit()

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, key=lambda x: x[1])
ans=0
i=0
for a, b in sorted_ab:
  for _ in range(b):
    if i < m:
      ans+=a
      i+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
drink = dict()
# 価格をkey, 本数をlist形式でvalueで格納するdict()
for i in range(N):
	value,number = map(int,input().split())
	drink.setdefault(value,[]).append(number)

drink = sorted(drink.items()) # keyを昇順ソート
value = 0
count = 0
for i in drink:
	
	# print('i:',i)
	if M <= i[1][0] : 
		# print('value:',M*i[0])
		value += M*i[0]
		M -= M
	else:
		# print('value:',i[0]*i[1][0])
		M -= i[1][0]
		value += i[0]*i[1][0]
	if M == 0:
		break
	# print('残りM:',M)
	# print('value_sum:',value)
print(value)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
drink = dict()
# 価格をkey, 本数をlist形式でvalueで格納するdict()
for i in range(N):
	value,number = map(int,input().split())
	drink.setdefault(value,[]).append(number)

drink = sorted(drink.items()) # keyを昇順ソート
value = 0
count = 0
for i in drink:
	# print('M:',M)
	# print('i:',i)
	if M <= i[1][0] : 
		# print('value:',M*i[0])
		value += M*i[0]
		M -= i[1][0]
		break
	else:
		# print('value:',i[0]*i[1][0])
		M -= i[1][0]
		value += i[0]*i[1][0]
	if M == 0:
		break
print(value)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
drink = dict()
# 価格をkey, 本数をlist形式でvalueで格納するdict()
for i in range(N):
	value,number = map(int,input().split())
	drink.setdefault(value,[]).append(number)

drink = sorted(drink.items()) # keyを昇順ソート
value = 0
count = 0
for i in drink:
	print('M:',M)
	print('i:',i)
	if M <= i[1][0] : 
		# print('value:',M*i[0])
		value += M*i[0]
		break
	else:
		# print('value:',i[0]*i[1][0])
		M -= i[1][0]
		value += i[0]*i[1][0]
	if M == 0:
		break
print(value)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
drink = dict()
# 価格をkey, 本数をlist形式でvalueで格納するdict()
for i in range(N):
	value,number = map(int,input().split())
	drink.setdefault(value,[]).append(number)

drink = sorted(drink.items()) # keyを昇順ソート
value = 0
count = 0
for i in drink:
	# print('M:',M)
	# print('i:',i)
	if M <= i[1][0] : 
		# print('value:',M*i[0])
		value += M*i[0]
		break
	else:
		# print('value:',i[0]*i[1][0])
		M -= i[1][0]
		value += i[0]*i[1][0]
print(value)

Submission status: Wrong Answer

Solution code:
li = list(input())
a = li.count("0")
import math
if a < math.ceil(len(li)/2):
    print(2*a)
else:
    print(2*(len(li)-a))

Submission status: Wrong Answer

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

data = [[0,0] for _ in range(n)]
for i in range(n):
  data[i][0],data[i][1] = map(int, input().split())

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

rest = m
money = 0
for a,b in data:
  #print(a,b)
  if b <rest:
    rest-=b
    money+=a*b
  else:
    money += a*rest
    print(money)

Submission status: Wrong Answer

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

data=[[0,0] for _ in range(n)]
for i in range(n):
  data[i][0],data[i][1] = map(int, input().split())

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

rest = m
money = 0
for a,b in data:
  #print(a,b)
  if b <rest:
    rest-=b
    money+=a*b
  else:
    money += a*rest
    print(money)

Submission status: Wrong Answer

Solution code:
N,M=map(int, input().split())
AB=[ [] for _ in range(N)]
for i in range(N):
  AB[i] = list( map(int, input().split()))
AB.sort()
print(AB)
cnt = ans = 0
for i in range(N):
  buy = AB[i][1]
  if cnt + AB[i][1] >= M:
    buy = M - cnt
  cnt += buy
  ans += buy * AB[i][0]
  print(buy,cnt,ans)
  if cnt >= M:
    break
print(ans)

Submission status: Wrong Answer

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

ab.sort()
ans=0
i=0
j=0
while i<m:
    ans+=ab[j][0]*ab[j][1]
    i+=ab[j][1]
    j+=1

print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
ab = sorted([ list(map(int, input().split())) for _ in range(n) ])
c = 0
for a, b in ab:
  if n <= b:
    c += a*n
    print(c)
    break
  else:
    c += a*b
    n -= b

Submission status: Wrong Answer

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

sorted_A_list = sorted(A_list)

def counter(x, l=A_list): #リストlに格納されている_xのインデックスを全て取得する
    return [i for i, _x in enumerate(l) if _x == x]


count_list = [0]
count = 0
ans = 0
if N == 1:
    ans = A_list[0] * M
else:
    for i in range(N):
        index_B_list = counter(sorted_A_list[i])
        for j in index_B_list: #その金額で最大何本買えるか
            count += B_list[j]
        count_list.append(count)
            
        if count_list[i+1] < M:
            ans += sorted_A_list[i] * (count_list[i+1] - count_list[i])
        else:
            ans += sorted_A_list[i] * (M - count_list[i])
            break

print(ans)

Submission status: Wrong Answer

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

sorted_A_list = sorted(A_list)

def counter(x, l=A_list): #リストlに格納されている_xのインデックスを全て取得する
    return [i for i, _x in enumerate(l) if _x == x]


count_list = [0]
count = 0
ans = 0
if N == 1:
    ans = A_list[0] * M
else:
    for i in range(N):
        index_B_list = counter(sorted_A_list[i])
        for j in index_B_list: #その金額で最大何本買えるか
            count += B_list[j]
        count_list.append(count)
            
        if count_list[i+1] <= M:
            ans += sorted_A_list[i] * (count_list[i+1]-count_list[i])
        else:
            ans += sorted_A_list[i] * (M - count_list[i])
            break

print(ans)

Submission status: Wrong Answer

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

sorted_A_list = sorted(A_list)

def counter(x, l=A_list): #リストlに格納されている_xのインデックスを全て取得する
    return [i for i, _x in enumerate(l) if _x == x]


count = 0
ans = 0
if N == 1:
    ans = A_list[0] * M
else:
    for i in range(N):
        index_B_list = counter(sorted_A_list[i])
        for j in index_B_list: #その金額で最大何本買えるか
            count += B_list[j]
            
        if count <= M:
            ans += sorted_A_list[i] * B_list[j]
        else:
            count -= B_list[j]
            ans += sorted_A_list[i] * (M - count)
            break

print(ans)

Submission status: Wrong Answer

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

sorted_A_list = sorted(A_list)

def counter(x, l=A_list): #リストlに格納されている_xのインデックスを全て取得する
    return [i for i, _x in enumerate(l) if _x == x]


count = 0
ans = 0
if N == 1:
    ans = A_list[0] * M
else:
    for i in range(N):
        index_B_list = counter(sorted_A_list[i])
        for j in index_B_list:
            count += B_list[j]
            
            if count <= M:
                ans += sorted_A_list[i] * B_list[j]
            else:
                count -= B_list[j]
                ans += sorted_A_list[i] * (M - count)
                break
        else:
            continue #正常にforループが終了したら外のforループを回す
        break #内側でbreakされたらbreakする

print(ans)

Submission status: Wrong Answer

Solution code:

import numpy as np

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=[]
for i in range(N):
    C.append([A[i],B[i]])
C = np.array(C)
C = C[np.argsort(C[:, 0])]

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

print(cost)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
dict = {}
for i in range(n):
	a, b = map(int, input().split())
	dict[a] = b
c = sorted(dict.keys())
ans = 0

for i in c:
	if m > dict[i]:
		m -= dict[i]
		ans += i * dict[i]
	else:
		ans += m * i
		break
print (ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
dict = {}
for i in range(n):
	a, b = map(int, input().split())
	dict[a] = b
c = sorted(dict.keys())
ans = 0

for i in c:
	if m >= dict[i]:
		m -= dict[i]
		ans += i * dict[i]
		if m == 0:
			break
	else:
		ans += m * i
		break
print (ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
dict = {}
for i in range(n):
	a, b = map(int, input().split())
	dict[a] = b
c = sorted(dict.keys())
ans = 0

for i in c:
	if m >= dict[i]:
		m -= dict[i]
		ans += i * dict[i]
	else:
		ans += m * i
		break
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.sort(key=lambda x: x[1])
ans = 0
#print(ab)
for i in range(n):
    if m == 0:
        break
    if m - ab[i][1] >= 0:
        ans += ab[i][0] * ab[i][1]
        m -= ab[i][1]
        #print(ans)
    else:
        ans += m * ab[i][0]
        #print(ans)
        break
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.sort(key=lambda x: x[1])
ans = 0
print(ab)
for i in range(n):
    if m == 0:
        break
    if m - ab[i][1] >= 0:
        ans += ab[i][0] * ab[i][1]
        m -= ab[i][1]
        #print(ans)
    else:
        ans += m * ab[i][0]
        #print(ans)
        break
print(ans)