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 _ 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[1]
        break
print(money)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
A=[list(map(int,input().split()))for i in range(n)]
print(A)
A=sorted(A,key=lambda y:y[0])
print(A)
cnt=0#ドリンクの本数
ans=0
for i in range(n):
    cnt+=A[i][1]
    if m<=cnt:
        over=cnt-m #mを超えた時の超過本数
        ans+=(A[i][0]*A[i][1])-(over*A[i][0])
        break
    else:
        ans+=A[i][0]*A[i][1]
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)]
l.sort(key=lambda x:x[0])
cnt=0
ans=0
num=0
while cnt<m:
  for i in range(n):
    cnt+=l[i][1]
    ans+=l[i][0]*l[i][1]
    num+=1
print(ans+(m-cnt)*l[num-1][0])

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 ab[i][1]==m:
        ans=ab[i][0]*m
        break
    elif ab[i][1]<m:
        ans+=ab[i][0]*ab[i][1]
        m-=ab[i][1]
    elif ab[i][1]>m:
        ans+=ab[i][0]*m
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
from bisect import bisect_left

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

A, B = zip(*sorted(zip(A, B)))  # A の小さい順

B_sum = np.cumsum(B)

ind = bisect_left(B_sum, M)

if ind == 0:
    ans = A[i] * M
else:
    ans = sum([A[i]*B[i] for i in range(ind)])

if M - B_sum[ind-1] > 0:
    ans += A[ind] * (M - B_sum[ind-1])

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
from bisect import bisect_left

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

A, B = zip(*sorted(zip(A, B)))  # A の小さい順

B_sum = np.cumsum(B)

ind = bisect_left(B_sum, M)

ans = sum([A[i]*B[i] for i in range(ind)])

if M - B_sum[ind-1] > 0:
    ans += A[ind] * (M - B_sum[ind-1])

print(ans)

Submission status: Wrong Answer

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

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

A.sort()
print(A)

nokori = M
yen = 0
mise = 0
while nokori > 0:
  if A[mise][1] >= nokori: #i番目の店で何本買えるか
    yen += A[mise][0]*nokori
    break
  else:
    yen += A[mise][0]*A[mise][1]
    nokori -= A[mise][1]
    mise += 1
print(yen)

Submission status: Wrong Answer

Solution code:
N, M = list(map(int,input().split()))
L = []
for i in range(N):
  L.append(list(map(int,input().split())))
L = sorted(L)
a = 0
c = 0
for i in range(N):
  a = a + L[i][1]
  if a > M:
    c = i
    break
p = 0
for j in range(c):
  p += L[j][0]*L[j][1]

p += L[c][0]*(M - a + L[c][1])

print(max(p,0))

Submission status: Wrong Answer

Solution code:
N, M = list(map(int,input().split()))
L = []
for i in range(N):
  L.append(list(map(int,input().split())))
L = sorted(L)
a = 0
c = 0
for i in range(N):
  a = a + L[i][1]
  if a > M:
    c = i
    break
p = 0
for j in range(c):
  p += L[j][0]*L[j][1]

p += L[c][0]*(M - a + L[c][1])

print(p)

Submission status: Wrong Answer

Solution code:
N, M = list(map(int, input().split()))
C = []
for n in range(N):
  A, B = list(map(int, input().split()))
  C.append([A,B])
  
C = sorted(C, key=lambda x:x[0])

S = 0
n = 0
while S <= M:
  S += C[0][1]
  n += 1
print(S)

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
  
c = 0
ans = 0
for key in sorted(list(d.keys())):
  if m-c <= d[key]:
    ans += key * (m-c)
    break
  else:
    c += d[key]
    ans += key * d[key]

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M = map(int, input().split())

AB = np.zeros(0, dtype=int)

for i in range(N):
    a, b = map(int, input().split())
    AB = np.concatenate([AB, np.full(b, a)])

AB = np.sort(AB)

print(AB[:M].sum())

Submission status: Wrong Answer

Solution code:
n,m = list(map(int,input().split()))
al=[]
bl=[]
for i in range(n):
    a,b = map(int,input().split())
    al.append(a)
    bl.append(b)
ans = 0
al_n = sorted(al)
for i in al_n:
    for j in range(bl[al.index(i)]):
        m-=1
        ans+=i
        if m==0:
            break
    else:
        continue
    break

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
def main():
    import sys
    input = sys.stdin.readline
    n,m=L()
    dic={}
    a=[]
    for i in range(n):
        ai,bi=L()
        if ai not in dic:
            dic[ai]=0
        dic[ai]+=bi
        a.append(ai)
    a.sort()
    a=list(set(a))
    ans=0
    drink=0
    tmp=0
    while drink<m:
        tmp=a.pop(0)
        for i in range(dic[tmp]):
            drink+=1
            ans+=tmp
            if drink>=m:
                break
    print(ans)
    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
def main():
    import sys
    input = sys.stdin.readline
    n,m=L()
    dic={}
    a=[]
    for i in range(n):
        ai,bi=L()
        if ai not in dic:
            dic[ai]=0
        dic[ai]+=bi
        a.append(ai)
    a.sort()
    a=list(set(a))
    ans=0
    drink=0
    tmp=0
    while drink<m:
        tmp=a.pop(0)
        if drink+dic[tmp]>m:
            tmp2=m-drink
            drink+=m-drink
            ans+=tmp2*tmp
        else:
            drink+=dic[tmp]
            ans+=dic[tmp]*tmp
    print(ans)
    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
def main():
    n,m=L()
    dic={}
    a=[]
    for i in range(n):
        ai,bi=L()
        if ai not in dic:
            dic[ai]=0
        dic[ai]+=bi
        a.append(ai)
    a.sort()
    ans=0
    drink=0
    tmp=0
    while drink<m:
        tmp=a.pop(0)
        if drink+dic[tmp]>m:
            tmp2=m-drink
            drink+=m-drink
            ans+=tmp2*tmp
        else:
            drink+=dic[tmp]
            ans+=dic[tmp]*tmp
    print(ans)
    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
pairs = [input().split() for _ in range(n)]
pairs.sort()
ans = 0
k = 0
while m>0:
    x = min(m,int(pairs[k][1]))
    ans += int(pairs[k][0])*x
    m -= x
    k += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
pairs = [input().split() for _ in range(n)]
pairs.sort()
count = 0
ans = 0
for i in pairs:
    ans += int(i[0])*int(i[1])
    count += int(i[1])
    if count >= m:
        ans -= int(i[0])*(count - m)
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
pairs = [input().split() for _ in range(n)]
pairs.sort(key = lambda x:x[0])
count = 0
ans = 0
for i in pairs:
    ans += int(i[0])*int(i[1])
    count += int(i[1])
    if count >= m:
        ans -= int(i[0])*(count - m)
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
pairs = [input().split() for _ in range(n)]
pairs.sort(key = lambda x:x[0])
print(pairs)
count = 0
ans = 0
for i in pairs:
    ans += int(i[0])*int(i[1])
    count += int(i[1])
    if count >= m:
        ans -= int(i[0])*(count - m)
        break
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N, M = list(map(int, input().split()))
A = []
for i in range(N):
    A.append(list(map(int, input().split())))
B = sorted(A, key=itemgetter(0))

m = 0
cost = 0

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

print(cost)

Submission status: Wrong Answer

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

amount = 0
for price, num in sorted_drinks:
    if m < num:
        amount += price*m
        break

    m -= num
    amount += price*num
print(amount)

Submission status: Wrong Answer

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

amount = 0
for d in sorted_drinks:
    if m < d[1]:
        amount += d[0]*m
        break

    m -= d[1]
    amount += d[0]*d[1]
print(amount)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
drinks = {}
for i in range(n):
    a, b = map(int, input().split())
    drinks[a] = b
sorted_drinks = sorted(drinks.items())
amount = 0
for d in sorted_drinks:
    if m > d[1]:
        m -= d[1]
        amount += d[0]*d[1]
    else:
        amount += d[0]*m
        print(amount)
        break

Submission status: Wrong Answer

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

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

ryoukin = 0
cnt = 0
for lst in d:
    for i in range(lst[1]):
        ryoukin += lst[0]
        cnt += 1
        if cnt >= m:
            break

print(ryoukin)

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
cnt = 0
for i in ab:
    a, b = i[0], i[1]
    if cnt + b >= m:
        print(ans + (m - cnt) * a)
    else:
        ans += a * b
        cnt += b

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
l = []
for i in range(n):
  a,b = map(int,input().split())
  l.append([a,b])
i = 0
count = 0
money = 0
while count < m:
  count += l[i][1]
  money = l[i][0]*l[i][1]
  i += 1
i -= 1
if count > m:
  money - (m-count)*l[i][1]
print(money)

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M = map(int, input().split())
a = [input().split() for i in range(N)]
# a = [[int(i[0]), int(i[1])] for i in a]
a = np.array(a, dtype='int64')
a = a[a[:, 0].argsort(), :]
print(a)

mysum = 0
coin = 0
for c in a:
    if mysum + c[1] < M:
        mysum += c[1]
        coin += c[0] * c[1]
    else:
        d = M - mysum
        coin += d * c[0]
        break

print(coin)

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M = map(int, input().split())
a = [input().split() for i in range(N)]
a = [[int(i[0]), int(i[1])] for i in a]
a = np.array(a,dtype= 'int64')
a = a[a[:, 0].argsort(), :]

sum = 0
coin = 0
for item in a:
    if item[1] + sum < M:
        sum += item[1]
        coin += item[0] * item[1]
    else:
        for i in range(1, item[1] + 1):
            if sum + i == M:
                print(coin + item[0] * i)
                break

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.append((a,b))

AB.sort()

cnt=0
ans=0
for a,b in AB:
    if cnt==m:
        print(ans)
        break
    temp=min(m-cnt,b)
    ans+=a*temp
    cnt+=temp

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.append((b,a))

AB.sort()

cnt=0
ans=0
for b,a in AB:
    if cnt==m:
        print(ans)
        break
    temp=min(m-cnt,a)
    ans+=b*temp
    cnt+=temp

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
import itertools


def sr(): return sys.stdin.readline().rstrip()


def ir(): return int(sr())


def lr(): return list(map(int, sr().split()))


N, M = lr()
d_list = []
for i in range(N):
    a, b = lr()
    d_list.append([a, b, i])

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

cnt = 0
ans = 0
for d in d_list:
    if (M - cnt) > d[1]:
        cnt += d[1]
        ans += d[1] * d[0]
    elif (M - cnt) > 0:
        ans += (M - cnt) * d[0]
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
def multi_input():
    return map(int, input().split())

N, M = multi_input()
AB = dict([list(multi_input()) for _ in range(N)])
ans = 0
for value, num in sorted(AB.items(), key=lambda x:x[0]):
    ans += value * min(num, M)
    M -= num
    if M <= 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.append((a,b))
drink.sort(reverse=1)

ans = 0
while m<0:
  a,b = drink.pop(-1)
  ans += a*min(m, b)
  m -= b
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N, M = map(int, input().split())
    store = list()
    for i in range(N):
        A, B = map(int, input().split())
        store.append([A, B])
    store.sort(key = lambda x : x[0])
    cost = 0
    drink = 0
    print(store)
    for i in range(N):
        if drink < M:
            if drink + store[i][1] < M:
                drink += store[i][1]
                cost += store[i][0] * store[i][1]
            else:
                cost += store[i][0] * (M - drink)
                drink += M - drink
        else:
            break
    print(cost)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
n, m = map(int, input().split())
a = [0] * n
b = [0] * n
s = 0
ans = 0
for i in range(n): a[i], b[i] = map(int, input().split())
D = sorted(dict(zip(a, b)).items(), key=lambda x: x)
for d in D:
    s += d[1]
    if s >= m:
        ans += d[0] * (m - (s - d[1]))
        print(ans)
        exit()
    else:
        ans += d[0] * d[1]

Submission status: Wrong Answer

Solution code:
a = list(map(int, input().split()))
N = a[0]
M = a[1]
price = 0
b = [list(map(int, input().split())) for i in range(N)]
lst = sorted(b)
for i in lst:
    if M < i[1]:
        price = price + i[0] * M
        print(price)
        break
    else:
        M = M - i[1]
        price = price + i[0] * i[1]

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
AB = [LIST() for _ in range(N)]

AB.sort(key = lambda x: (x[0], x[1]))

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

Submission status: Wrong Answer

Solution code:
n, m = [int(i) for i in input().split()]
ab = [[int(i) for i in input().split()] for j in range(n)]
ab = sorted(ab, key=lambda x:x[0])

sm = 0
i = 0
for i in ab:
    if m > i[1]:
        sm += i[0] * i[1]
        m -= i[1]
    else:
        sm += i[0] * m
        break
print(ab)

Submission status: Wrong Answer

Solution code:
n, m = [int(i) for i in input().split()]
d = sorted({i[0]: i[1] for i in [[int(j) for j in input().split()] for k in range(n)]}.items(), key = lambda x:x[0])
sm = 0
i = 0
for i in d:
    if m > i[1]:
        sm += i[0] * i[1]
        m -= i[1]
    else:
        sm += i[0] * m
        break
print(sm)

Submission status: Wrong Answer

Solution code:
def resolve():
    n, m = map(int, input().split())
    l = [list(map(int, input().split())) for _ in range(n)]
    l.sort()
    ans = 0
    drink = 0
    for i in range(n):
        cost = l[i][0]
        num = l[i][1]
        if drink + num >=m:
            ans += cost*(m-drink)
            print(ans)
        else:
            drink += num
            ans += num*cost

resolve()

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
a.sort(key=lambda x:(x[0],x[1]))
c = 0
ans = 0
for i in range(n):
    if c >= m:
        break
    for j in range(a[i][1]):
        if c < m:
            c += 1
            ans += a[i][0]

Submission status: Wrong Answer

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

mise={}
for i in range(n):
    a,b=[int(j) for j in input().split()]
    if a in mise:
        mise[a]+=b
    else:
        mise[a]=b
nedan=list(mise.keys())
nedan.sort()
i=0
ans=0
while m:
    honnsuu=mise[nedan[i]]
    kauno=min(honnsuu,m)
    ans+=kauno*nedan[i]
    i+=1
    m=m-kauno
print(mise)    
print(nedan)
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a, b = [], []
for i in range(n):
    te, mp = map(int, input().split())
    a.append(te)
    b.append(mp)

e, f = [], []
for i, j in sorted(zip(a, b)):
    e.append(i)
    f.append(j)

ans = 0
for i in range(n):
    if m - f[i] < 0:
        ans += e[i] * m
        print(ans)
        break
    else:
        ans += f[i] * e[i]
        m -= f[i]

Submission status: Wrong Answer

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

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

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

money = 0
cnt = 0
for i in range(N):
    for j in range(A[i][1]):
        money += A[i][0]
        if cnt == N:
            print(money)
            break

Submission status: Wrong Answer

Solution code:
import heapq
N, M = [int(i) for i in input().split()]
zaiko={}
value = []
heapq.heapify(value)
for i in range(N):
    #在庫の本数。一本あたりの代金
    b,a=[int(i)for i in input().split()]
    heapq.heappush(value,b)
    if  b not in zaiko:
        zaiko[b]=a
    else:
        zaiko[b]+=a

cnt=0
sumval=0
while True:
    if cnt == M: 
       print(sumval)
       exit()
    minival = heapq.heappop(value)
    minicnt = zaiko[minival]
    #print("minival,minicnt={},{}".format(minival,minicnt))
    if cnt + minicnt <= M:
       cnt+=minicnt
       sumval += minival * minicnt
    else:
       sumval += minival * (M-cnt)
       cnt=M

Submission status: Wrong Answer

Solution code:
import heapq
N, M = [int(i) for i in input().split()]
zaiko={}
value = []
heapq.heapify(value)
for i in range(N):
    #在庫の本数。一本あたりの代金
    b,a=[int(i)for i in input().split()]
    heapq.heappush(value,b)
    if  b not in zaiko:
        zaiko[b]=a
    else:
        zaiko[b]+=a

cnt=0
sumval=0
while True:
    if cnt == M: 
       print(sumval)
       exit()
    minival = heapq.heappop(value)
    minicnt = zaiko[minival]
    #print("minival,minicnt={},{}".format(minival,minicnt))
    if cnt + minicnt <= M:
       cnt+=minicnt
       #print(cnt)
       sumval += minival * minicnt
    else:
       sumval += minival * (M-cnt)
       print(sumval)
       exit()

Submission status: Wrong Answer

Solution code:
n, m = [int(i) for i in input().split()]
ab = [[int(j) for j in input().split()] for i in range(n)]
k = {}
for i in range(len(ab)):
    k.update({ab[i][0]: ab[i][1]})

sorted_ab = sorted(k.items(), key=lambda x: x[0])

sm = 0
for i in sorted_ab:
    if i[1] <= m:
        m -= i[1]
        sm += i[0] * i[1]
    else:
        sm += i[0] * m
        break

print(sm)

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])
s=0 #本数
t=0 #値段
for i in range(N):
  s+=A[i][1]
  if M>s:
    t+=A[i][0]*A[i][1]
  else:
    over=s-M
    t+=A[i][0]*A[i][1]-A[i][0]*over
print(t)

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])
s=0 #本数
t=0 #値段
for i in range(N):
  s+=A[i][1]
  if M>s:
    t+=A[i][0]*A[i][1]
  else:
    over=s-M
    t-=A[i][0]*over
print(t)

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])
s=0 #本数
t=0 #値段
for i in range(N):
  if M>s:
    s+=A[i][1]
    t+=A[i][0]*A[i][1]
  else:
    over=s-M
    t-=A[i-1][0]*over
print(t)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
a = [i[0] for i in ab]
b = [i[1] for i in ab]
sa = sorted(a)
cnt = 0
ans = 0
for i in sa:
    if cnt + b[a.index(i)] > m:
        print(ans + i * (m - cnt))
        exit()
    else:
        cnt += b[a.index(i)]
        ans += i * b[a.index(i)]
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.append([a,b])

ab.sort()
ans = 0
if len(ab) == 1:
  if m >= ab[0][1]:
    print(ab[0][0] * ab[0][1])
    exit()
  else:
    print(ab[0][0] * m)
    exit()


for i, j in ab:
  for k in range(j):
    if m != 0:
      print(m)
      m -= 1
      ans += i
    else:
      print(ans)
      exit()

Submission status: Wrong Answer

Solution code:
from functools import reduce
N, M = map(int,input().split())
ary1 =[]
for x in range(N):
  ary1.append(list(map(int,input().split())))

ary2 = sorted(ary1)
print(ary2)
count = 0
total_sum = 0
for i in range(N):
  if count + ary2[i][1] <= M:
    total_sum += ary2[i][0] * ary2[i][1]
    count += ary2[i][1]
  elif count > M :
    break
  else:
    zan = M - count
    total_sum += ary2[i][0] * zan
    count += zan

print(total_sum)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
a = []
for i in range(n):
    a.append(x[i][0])
b = []
for i in range(n):
    b.append(x[i][1])
    
a.sort()
p = 0
price = 0
for i in range(n):
    for j in range(n):
        if (a[i] == x[j][0]):
            p += x[j][1]
            if (p >= m):
                price += (x[j][0]*x[j][1]-x[j][0]*(p-m))
                print(price)
                exit()
            else:
                price += x[j][0]*x[j][1]

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
a = []
for i in range(n):
    a.append(x[i][0])
b = []
for i in range(n):
    b.append(x[i][1])
    
a.sort()
print(a)
p = 0
price = 0
for i in range(n):
    for j in range(n):
        if (a[i] == x[j][0]):
            p += x[j][1]
            if (p >= m):
                price += (x[j][0]*x[j][1]-x[j][0]*(p-m))
                print(price)
                exit()
            else:
                price += x[j][0]*x[j][1]

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab = sorted(ab, key=lambda x:x[0])
print(ab)
ans = 0
d = 0
i = 0
while d < m:
  ans += ab[i][0]*min(m-d,ab[i][1])
  d += ab[i][1]
  i += 1
print(ans)

Submission status: Wrong Answer

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

ArA = [0]*n
ArB = [0]*n

for i in range(n):
	a,b = map(int, input().split())
	ArA[i] = a
	ArB[i] = b
	print(a,b)
#Sort
for j in range(n):
	mind = ArA[j]
	ind=j
	for i in range(j,n):
		if ArA[i] <= mind:
			ind=i
			mind=ArA[i]
	tmp = ArA[ind]
	ArA[ind]=ArA[j]
	ArA[j]=tmp
	tmp = ArB[ind]
	ArB[ind]=ArB[j]
	ArB[j]=tmp
		
    
print(ArA, ArB)

Submission status: Wrong Answer

Solution code:
import sys
N,M = map(int,input().split())
shops = dict()
price = []
takahashi = 0
money = 0
for i in range(N):
    bottle,stock = map(int,input().split())
    if bottle not in shops:
        shops[bottle] = 0
    shops[bottle] += stock
    if bottle not in price:
        price.append(bottle)
price.sort()
for y in price:
    while takahashi != M:
        if shops[y] <= (M-takahashi):
            takahashi += shops[y]
            money += shops[y]*y
            shops[y] = 0
            break
        else:
            takahashi += (M-takahashi)
            shops[y] -= (M-takahashi)
            money += y*(M-takahashi)
            break
    if takahashi == M:
        print(money)
        sys.exit(0)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
A = {}
for i in range(n):
  a, b = map(int, input().split())
  if not a in A:
    A[a] = b
  else:
    A[a] += b
ans = 0
num = 0
for k, v in A.items():
  if num < m and m <= num+v:
    ans += (m-num)*k
    break
  else:
    ans += v*k
    num += v
print(ans)

Submission status: Wrong Answer

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

S = [[0]*2 for i in range(N)]
for i in range(N):
    S[i] = list(map(int, input().split()))
     
S = sorted(S)
print(S)

quantitys = 0
total = 0

for i in range(N):
    # この店を買い尽くしてもまだ足りなければ、全部買う
    if((M - quantitys) - S[i][1])>=0:
        quantitys += S[i][1]
        total += S[i][0] * S[i][1]
    else:
        quantity = M - quantitys
        quantitys += quantity
        total += S[i][0] * quantity
    if M-quantitys == 0:
        break

print(str(total))

Submission status: Wrong Answer

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

S = [[0]*2 for i in range(N)]
for i in range(N):
    S[i] = list(map(int, input().split()))
     
S = sorted(S)

quantitys = 0
total = 0

for i in range(N):
    # この店を買い尽くしてもまだ足りなければ、全部買う
    if((M - quantitys) - S[i][1])>=0:
        quantitys += S[i][1]
        total += S[i][0] * S[i][1]
    else:
        quantity = M - quantitys
        quantitys += quantity
        total += S[i][0] * S[i][1]
    if M-quantitys == 0:
        break

print(str(total))

Submission status: Wrong Answer

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

S = [[0]*2 for i in range(N)]
for i in range(N):
    S[i] = list(map(int, input().split()))
     
S = sorted(S)

quantitys = 0
total = 0

for i in range(N):
    # この店を買い尽くしてもまだ足りなければ、全部買う
    if((N - quantitys) - S[i][1])>=0:
        quantitys += S[i][1]
        total += S[i][0] * S[i][1]
    else:
        quantity = N - quantitys
        quantitys += quantity
        total += S[i][0] * S[i][1]
    if N-quantitys == 0:
        break

print(str(total))

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

res = 0
cnt = 0
for i in sorted(d):
    if(d[i] <= M):
        res += d[i]*i
        M -= d[i]
    else:
        res += M * i
        break

print(res)

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

res = 0
for i in sorted(d):
    if(d[i] <= M):
        res += d[i]*i
        M -= d[i]
    else:
        res += M * i
        break

print(res)

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

res = 0
cnt = 0
for i in sorted(d):
    if(d[i] <= M):
        res += d[i]*i
        M -= d[i]
    elif(M > 0):
        res += M * i
        break
    else:
        break
print(res)

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

res = 0
cnt = 0
for i in sorted(d):
    if(d[i] <= M):
        res += d[i]*i
        M -= d[i]
    else:
        res += M * i
        break
print(res)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab = sorted(ab,key=lambda x:x[0])
ans = 0
for i in ab:
  m -= i[1]
  ans += i[0]*i[1]
  if m <= 0:
    print(ans + m*i[0])
    break
  elif i == ab[-1]:
    print(ans)
    break

Submission status: Wrong Answer

Solution code:
def main():
    N, M = map(int, input().split())
    A = [[0, 0] for _ in range(N)]
    for i in range(N):
        A[i][0], A[i][1] = map(int, input().split())
    
    cnt = 0
    money = 0
    A.sort(key=lambda x:x[0])
    for i in range(N):
        if(cnt < M):
            money += A[i][0]*A[i][1]
            cnt += A[i][1]
        else:
            break
    if(cnt == M):
        print(money)
    else:
        print(money-(cnt-M)*A[i-1][0])
    
main()

Submission status: Wrong Answer

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

bought = 0
ans = 0

if n == 1:
    print(a[0][0]*m)
    exit()

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

for i in range(n):
    remain = m - bought
    if a[i][0] <= remain:
        ans += a[i][0] * a[i][1]
        bought += a[i][1]
    else:
        ans += a[i][0]*remain
        break

print(ans)

Submission status: Wrong Answer

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

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

bought = 0
ans = 0

if len(a) == 1:
    print(a[0][0]*m)
    exit()

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

for i in range(n):
    remain = m - bought
    if a[i][0] < remain:
        ans += a[i][0] * a[i][1]
        bought += a[i][1]
    else:
        ans += a[i][0]*remain
        break

print(ans)