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())

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

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

for val in dic:
    new_dic[val[0]] = val[1]

ans = 0

#print(new_dic)

for k,v in new_dic.items():
    if m - v > 0:
        ans += k*v
        m = m-v

    elif m - v <= 0:
        ans += k*m
        print(ans)
        exit()

Submission status: Wrong Answer

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

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

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

for val in dic:
    new_dic[val[0]] = val[1]

ans = 0

#print(new_dic)

for k,v in new_dic.items():
    if m - v > 0:
        ans += k*v

    elif m - v <= 0:
        ans += k*m
        print(ans)
        exit()

    m = m-v

print(ans)

Submission status: Wrong Answer

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

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

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

for val in dic:
    new_dic[val[0]] = val[1]

ans = 0

print(new_dic)

for k,v in new_dic.items():
    if m - v > 0:
        ans += k*v

    elif m - v <= 0:
        ans += k*m
        print(ans)
        exit()

    m = m-v

print(ans)

Submission status: Wrong Answer

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

for m in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)

#print(A,B)

A_sorted=sorted(A)
#print(A_sorted)

for a in A_sorted:
    #print(B[A.index(a)])
    b=B[A.index(a)]
    
    c+=b
    y+=a*b

    if c>=M:
        print(y-a*(c-M))
        break

    """
    if c+b>=M:
        print(y+(M-c)*a)
        exit()
    else:
        c+=b
        y+=a*b
    #print("count: {}\nmoney: {}\n".format(c,y))
    """

Submission status: Wrong Answer

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

for m in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)

#print(A,B)

A_sorted=sorted(A)
#print(A_sorted)
for a in A_sorted:
    #print(B[A.index(a)])
    b=B[A.index(a)]
    if c+b>=M:
        print(y+(M-c)*a)
        exit()
    else:
        c+=b
        y+=a*b
    #print("count: {}\nmoney: {}\n".format(c,y))

Submission status: Wrong Answer

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

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

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

for val in dic:
    new_dic[val[0]] = val[1]

ans = 0



for k,v in new_dic.items():
    if m - v >= 0:
        ans += k*v

    elif m - v < 0:
        ans += k*m
        print(ans)
        exit()

    m = m-v

print(ans)

Submission status: Wrong Answer

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

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

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

for val in dic:
    new_dic[val[0]] = val[1]

ans = 0

for k,v in new_dic.items():
    if m - v >= 0:
        ans += k*v

    elif m - v < 0:
        ans += k*m
        print(ans)
        exit()

    m = m-v

Submission status: Wrong Answer

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

pay = 0
to = 0
j = 0
while to < m:
	if to+ab[A[j]] <= m:
		to += ab[A[j]]
		pay += A[j]*ab[A[j]]
		j += 1
	else:
		pay += A[j]*(m-to)
		to = m

print(pay)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
cost=0
amount=m
for i in range(n):
    if amount>0:
        print('am:',amount)
        if amount > ab[i][1]:
            cost+=ab[i][0]*ab[i][1]
            amount-=ab[i][1]
        else:
            cost+=ab[i][0]*amount
            break
print(cost)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
prices = []
for i in range(n):
    prices.append(0)
    a, b = input().split()
    prices[i] = a + "_" + b
    
prices.sort()
k = m 
ans = 0
for i in range(n):
    if k > int(prices[i].split("_")[1]):
        k -= int(prices[i].split("_")[1])
        ans += int(prices[i].split("_")[0]) * int(prices[i].split("_")[1])
    else:
        ans += k * int(prices[i].split("_")[0])
        break

print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
D = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: x[1])
# 単価, 購入可能本数

cnt = 0
total = 0
for d in D:
    tmp_cnt = cnt + d[1]
    if tmp_cnt < m:
        total += d[0] * d[1]
        cnt += d[1]
    else:
        sub = m - cnt
        if d[1] >= sub:
            total += d[0] * sub  # sub個分売ってないパターンは？
            cnt += sub
            break
        else:
            total += d[0] * d[1]
            cnt += d[1]

print(total)

# [[2, 5], [7, 9], [3, 10], [6, 18]]
# 3までで103円, 24本
# 残り6本。→ 36円
# 合計 139円

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
N,M = map(int,input().split())
A = np.zeros(N,dtype="int64")
B = np.zeros(N,dtype="int64")
A2 = []
B2 = []
s = 0
ans = 0
for i in range(N):
    A1,B1=[int(i) for i in input().split()]
    A2.append(A1)
    B2.append(B1)
A = A2
B = B2
An =sorted(A)
for i in range (0,N):
  p = A.index(An[i])
  if s + B[p] >= M:
    ans = ans + (M - s) * A[p]
    print(ans)
    sys.exit()
  s = s + B[p]
  ans = ans + A[p] * B[p]

Submission status: Wrong Answer

Solution code:
import sys
N,M = map(int,input().split())
A = []
B = []
s = 0
ans = 0
for i in range(N):
    A1,B1=[int(i) for i in input().split()]
    A.append(A1)
    B.append(B1)
An =sorted(A)
for i in range (0,N):
  p = A.index(An[i])
  if s + B[p] >= M:
    ans = ans + (M - s) * A[p]
    print(ans)
    sys.exit()
  s = s + B[p]
  ans = ans + A[p] * B[p]

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
l = [map(int, input().split()) for i in range(n)]
ans = 0
for a,b in l:
  if b >= m:
    ans += a * (b-m)
    break
  else:
    ans += a*b
    m -= b
print(ans)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
Xa={}
ans=0
for i in range(N):
    V,S=map(int,input().split())
    Xa[V]=S
Xb=sorted(Xa.items())
for i in range (len(Xb)) :
    M -= Xb[i][1]
    ans += Xb[i][0]*Xb[i][1]
    if M <= 0 :
        ans -= abs(M)*Xb[i][0]
        break

print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N, M = map(int, input().split())
d = dict()
for _ in range(N):
    price, amount = map(int, input().split())
    d[price] = amount

ans = 0
for price, amount in sorted(d.items(), key=itemgetter(0)):
    if M <= 0:
        break

    if amount < M:
        M -= amount
        ans += price * amount
    else:
        ans += price * M
        M = 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_s=sorted(AB)

ans=0
cnt=0
for a,b in AB_s:
    ans+=a*b
    cnt+=b
    if cnt>M:
        ans-=a*(cnt-M)
        print(ans)
        exit()

Submission status: Wrong Answer

Solution code:
import sys
min_money = 0
count = 0
n,m = map(int,input().split())
ab_list = [input().split() for _ in range(n)]
ab_list.sort()
for i in range(n):
    for a,b in zip(ab_list[i][0],ab_list[i][1]):
        for j in range(1,int(b)+1):
            if count == m:
                sys.exit
            min_money += int(a)
            count += 1
print(min_money)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
A = []
for _ in range(N):
    a,b = map(int,input().split())
    A.append((a,b))
A = sorted(A,key=lambda x:x[0])
B = [A[0][1]]
ind = 0
for i in range(1,N):
    B.append(B[i-1]+A[i][1])
    if B[i]>=M:
        ind = i
        break
if ind>0:
    cnt = 0
    for i in range(ind):
        cnt += A[i][0]*A[i][1]
    cnt += A[ind][0]*(M-B[ind-1])
else:
    cnt = A[0][0]*M
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
N,M=map(int,input().split())
A=[0]*N
B=[0]*N
for i in range(0,N):
  A[i],B[i]=map(int,input().split())
index=sorted(range(len(A)), key=lambda k: A[k])
cost=0
get=0
for i in index:
  if get+B[i]<=M:
    get += B[i]
    cost += A[i]*B[i]
  else:
    cost += A[i]*(M-get)
    print(cost)
    sys.exit()

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
L=[]
for _ in range(N):
  L.append(list(map(int,input().split())))
L.sort()
ans=0
while M>0:
  for l in L:
    ans+=l[0]*min(M,l[1])
    M-=l[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)]

c = sorted(ab, key= lambda x:x[0])
s = [0]
for i in range(n):
    s.append(s[i] + c[i][1])
    if s[i] <= m <= s[i+1]:
        stop = i

ans=0
for i in range(stop):
    ans += c[i][0]*c[i][1]
    print(ans)
while s[stop] < m:
    ans += c[stop][0]
    s[stop] += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from operator import itemgetter
n, m = [int(i) for i in input().split()]
lst = []
for i in range(n):
    a, b = map(int, input().split())
    lst.append([a, b])

lst = sorted(lst, key=itemgetter(1))

money = 0
now = 0

for e in lst:
    if now + e[1] < m:
        now += e[1]
        money += e[0] * e[1]
    else:
        money += e[0] * (m - now)
        print(money)
        sys.exit()

Submission status: Wrong Answer

Solution code:
#import pysnooper
#import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)
input=stdin.readline

n,m=map(int,input().split())
a=sorted([list(map(int,input().split())) for _ in range(n)])
print(a)
cnt,can=0,0
for i in range(n):
    if can+a[i][1]<m:
        cnt+=a[i][0]*a[i][1]
        can+=a[i][1]
    else:
        cnt+=a[i][0]*(m-can)
        break
    #print(cnt)
print(cnt)

Submission status: Wrong Answer

Solution code:
#import pysnooper
#import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)
input=stdin.readline

n,m=map(int,input().split())
a=sorted([list(map(int,input().split())) for _ in range(n)])
cnt,can=0,0
for i in range(n):
    if cnt+a[i][1]<m:
        cnt+=a[i][0]*a[i][1]
        can+=a[i][1]
    else:
        b=m-can
        cnt+=a[i][0]*b
        break
    #print(cnt)
print(cnt)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
dic = {}
for i in range(n):
    a, b = map(int, input().split())
    dic[a] = b
dic = sorted(dic.items(), key=lambda x:x[0])
get = 0
money = 0
for i in dic:
    if get + i[1] <= m:
        get += i[1]
        money += i[0]*i[1]
    else:
        money += (m-get)*i[0]
        print(money)
        exit()

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
dic = {}
for i in range(n):
    a, b = map(int, input().split())
    dic[a] = b
dic = sorted(dic.items(), key=lambda x:x[0])
get = 0
money = 0
for i in dic:
    if get + i[1] <= m:
        get += i[1]
        money += i[0]*i[1]
    else:
        money += (m-get)*i[0]
        break
print(money)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N,M=map(int,input().split())
l=[10**5]*M

for i in range(N):
    a,b=map(int,input().split())
    
    count=0
    for j in range(M):
        if l[j]>a:
            del l[0]
            l.append(a)
            count+=1
        l.sort(reverse=True)
        if count==b:
            break

print(l)
print(sum(l))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = [0] * (n + 1)
b = [0] * (n + 1)
price = [0] * (n + 1)
ans = 0

shop = [tuple(map(int, input().split())) for _ in range(n)]
shop.sort()

for i in range(1, n + 1):
    a_i, b_i = shop[i - 1]
    a[i] = a[i - 1]
    b[i] = b[i - 1]
    price[i] = a_i
    a[i] += a_i * b_i
    b[i] += b_i

for i in range(1, n + 1):
    if m <= b[i]:
        m = m - b[i - 1]
        print(m)
        ans = a[i - 1] + price[i] * m
        break
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N,M=map(int,input().split())
l=[10**5]*M

for i in range(N):
    a,b=map(int,input().split())
    
    count=0
    for j in range(M):
        if l[j]>a:
            l[j]=a
            count+=1
        l.reverse()
        if count==b:
            break

print(l)
print(sum(l))

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])
answer = 0
for ab in AB:
    if M - ab[1] <= 0:
        answer += M * ab[0]
    else:
        answer += ab[0] * ab[1]
        M -= ab[1]
print(answer)

Submission status: Wrong Answer

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

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

purchased = 0
ans = 0
for k, v in sorted(d.items(), key=lambda x: x[0]):
    if M == 0:
        break
    q = min(v, M)
    M -= q
    ans += k * q

print(ans)

Submission status: Wrong Answer

Solution code:
N,M = [int(s) for s in input().split()]
lst = []

for i in range(N):
  lst = lst + [[int(s) for s in input().split()]]

lst.sort()
n = 0
cost = 0

for e in lst:
    n += e[1]
    cost += e[0] * e[1]
    if n >= M:
        break

if n > M:
  cost -= lst[i][0] * (n - M)

print(cost)

Submission status: Wrong Answer

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

num_drinks = 0
sum_prices = 0
for price, num in sorted_drinks:
    num_drinks += num
    sum_prices += num * price
    if num_drinks > m:
        sum_prices -= (num_drinks - m) * price
        break
    elif num_drinks == m:
        break

print(sum_prices)

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())))
    
sab = sorted(ab,key=lambda x:x[0])
cost = 0
for i in sab:
	print(cost,m)
	if m - i[1] > 0:
		m -= i[1]
		cost += i[0] * i[1]
	else:
		for j in range(m):
			cost += i[0]
		break
print(cost)

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())))
    
sab = sorted(ab,key=lambda x:x[0])
cost = 0
for i in sab:
	if m - i[1] > 0:
		m -= i[1]
		cost += i[0] * i[1]
	else:
		for j in range(m):
			cost += i[0]
print(cost)

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())))
sab = sorted(ab,key=lambda x:x[0])

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(key=lambda x: x[0])

c = 0
ans = 0
for i,j in AB:
  c += j
  if c < m:
    ans += i*j
  else:
    ans += i*(m-(c-j))

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin

n,m=map(int,input().split())
l = [stdin.readline().rstrip().split() for _ in range(n)]

l.sort()
ans=0
for i,j in l:
    a=min(m,int(j))
    ans+=a*int(i)
    m-=a
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin

n,m=map(int,input().split())
l = [stdin.readline().rstrip().split() for _ in range(n)]

l.sort()
a=0
ans=0
for i,j in l:
    for k in range(int(j)):
        if a>m-1:
            break
        else:
            ans+=int(i)
            a+=1
            
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin

n,m=map(int,input().split())
l = [stdin.readline().rstrip().split() for _ in range(n)]

l.sort()
a=0
ans=0
for i,j in l:
    for k in range(int(j)):
        if a>=m:
            break
        else:
            ans+=int(i)
            a+=1

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin

n,m=map(int,input().split())
l = [stdin.readline().rstrip().split() for _ in range(n)]

l.sort()
a=0
ans=0
for i,j in l:
    aa=int(i)
    aaa=int(j)
    for k in range(aa):
        if a==m:
            print(ans)
            exit()
        else:
            ans+=int(aaa)
            a+=1

Submission status: Wrong Answer

Solution code:
from sys import stdin

n,m=map(int,input().split())
l = [stdin.readline().rstrip().split() for _ in range(n)]

l.sort()
a=0
ans=0
for i,j in l:
    for k in range(int(j)):
        if a==m:
            print(ans)
            exit()
        else:
            ans+=int(i)
            a+=1

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())
L = []
ans, cnt = 0, 0
for i in range(n):
  ab = list(map(int,input().split()))
  L.append(ab)
L.sort()
for j in range(n):
  if m-cnt>=L[j][1]:
    cnt+=L[j][1]
    ans+=L[j][0]*L[j][1]
  else:
    ans+=L[j][0]*(m-cnt)
    break
  if ans==m:
    break
print(ans)

Submission status: Wrong Answer

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

an=0
for i in range(n):
    if m > int(li[i][1]):
        an+=int(li[i][0])*int(li[i][1])
        m-=int(li[i][1])
    else:
        an+=m*int(li[i][0])
        print(an)
        exit()

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
date = []
for i in range(N):
  AB_list = list(map(int,input().split()))
  date.append(AB_list)
date.sort()
ans = 0
i = 0
while True:
  if (date[i][0]<=M):
    ans+=date[i][0]*date[i][1]
    M-=date[i][1]
  else:
    ans += date[i][0]*M
    break
  i+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
date = []
for i in range(N):
  AB_list = list(map(int,input().split()))
  date.append(AB_list)
date.sort()
ans = 0
i = 0
while True:
  if (date[i][0]<=M):
    ans+=date[i][0]*date[i][1]
    M-=date[i][1]
  else:
    ans += date[i][1]*M
    break
  i+=1
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 = A.copy()
C.sort()

count = 0
money = 0
i = 0

while count < M:
    money += C[i] * B[A.index(C[i])]
    count += B[A.index(C[i])]
    i += 1

if count > M:
    tmp = count - M
    money -= C[i-1]*tmp

ans = money
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())

A.sort()

print(1)

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())

A.sort()

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
price_dic = {}
remaining = M
cost = 0

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

price_dic = sorted(price_dic.items())

while remaining > 0:
    for price, bottles in price_dic:
        cost += price * min(remaining, bottles)
        remaining -= min(remaining, bottles)

print(cost)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
price_dic = {}
remaining = M
cost = 0

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

price_dic = sorted(price_dic.items())

while remaining > 0:
    for A, B in price_dic:
        if remaining > B:
            cost += A * B
            remaining -= B
        else:
            cost += A * remaining
            remaining = 0

print(cost)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort()
cost = 0
count = 0
for A, B in AB:
    if M-cost > B:
        cost += B*A
        count += B
    elif count < M:
        cost += (M-count)*A
        count += M - count
    else:
        break
print(cost)

Submission status: Wrong Answer

Solution code:
from pprint import pprint
def main():
    N,M = map(int,input().split())
    store_l = []
    for i in range(N):
        store_l.append(tuple(map(int,input().split())))

    store_l = sorted(store_l,key=lambda x:x[0])
    pprint(store_l)
    ans = 0
    buynum = 0
    for price,maxnum in store_l:
        if(buynum+maxnum<=M):
            buynum += maxnum
            ans += maxnum*price
        else:
            ans += (M-buynum)*price
            break
    print(ans)

if __name__=="__main__":
    main()

Submission status: Wrong Answer

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

ab = [[int(l[0]), int(l[1])] for l in (input().split() for i in range(n))]
ab.sort()
temp = sum(ab, [])  # 疑似Flatten
a, b = temp[0::2], temp[1::2]
print(a, b)

count, index, remainder = 0, 0, 0

for i in range(n):
  if count + b[i] < m:  
    count += b[i]
  else:
    index = i
    remainder = m - count
    
total = a[index] * remainder
# print(a[index])
# print(remainder)
# print(total)

for i in range(index):
  total += a[i] * b[i]

print(total)

Submission status: Wrong Answer

Solution code:
n,m  =map(int,input().split())
lm = []
for _ in range(n):
    lm.append(list(map(int,input().split())))
s = 0
mon = 0
lm.sort(key = lambda x:x[0])
while s < m:
    s += 1
    print(s)
    mon += lm[0][0]
    lm[0][1] -= 1
    print(lm)
    if lm[0][1] == 0:
        lm = lm[1::]
print(mon)

Submission status: Wrong Answer

Solution code:
# Aiで貪欲する
n, m = map(int, input().split())
h = dict()
for _ in range(n):
    k, v = map(int, input().split())
    h[k] = v
h = sorted(h.items(), key=lambda x: x[0])


ans = 0
for k, v in h:
    while v > 0:
        if m <= 0:
            print(ans)
            exit()
        else:
            v -= 1
            ans += k
            m -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
# Aiで貪欲する
n, m = map(int, input().split())
h = dict()
for _ in range(n):
    k, v = map(int, input().split())
    h[k] = v
h = sorted(h.items(), key=lambda x: x[0])


ans = 0
for k, v in h:
    while v > 0:
        if m <= 0:
            print(ans)
            exit()
        else:
            v -= 1
            ans += k
            m -= 1

Submission status: Wrong Answer

Solution code:
# Aiで貪欲する
n, m = map(int, input().split())
h = dict()
for _ in range(n):
    k, v = map(int, input().split())
    h[k] = v
h = sorted(h.items(), key=lambda x: x[0])


ans = 0
for k, v in h:
    while v > 0:
        if m <= 0:
            exit()
        else:
            v -= 1
            ans += k
            m -= 1

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin

N, M = [int(x) for x in stdin.readline().rstrip().split()]
drink = {}
for i in range(0, N):
    a, b = [int(x) for x in stdin.readline().rstrip().split()]
    drink[a] = b

cost = 0
buy_drinks = 0
for price, num in sorted(drink.items()):
    if buy_drinks + num > M:
        cost += (M-buy_drinks) * price
        buy_drinks = M
        break
    else:
        cost += price * num
        buy_drinks += num

print(cost)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

AB.sort()

cnt = 0
yen = 0

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

answer = yen
print(answer)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

AB.sort()

cnt = 0
yen = 0

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
a = []
b = []
ans = 0
for i in range(n):
    _a,_b = map(int,input().split())
    a.append(_a)
    b.append(_b)
sa = sorted(a)
for i in range(n):
    num = b[a.index(sa[i])]
    if num <= m:
        m -= num
        ans += sa[i]*num
    else:
        ans += sa[i]*m
        m = 0
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
ab = []
for n in range(N):
    a,b = map(int,input().split())
    ab.append((a,b))
ab.sort()
coin = 0
cnt = 0
for n in range(N):
    cnt += ab[n][1]
    if cnt >= M:
        coin += (cnt - M) * ab[n][0]
        print(coin)
        break
    coin += ab[n][1] * ab[n][0]

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
L=[]
for i in range(N):
  L.append(list(map(int,input().split())))
L.sort()
T=0
P=0
for i in L:
  if T>M:
    print(M*i[0])
    break
  elif T+i[1]>M:
    print(P+i[0]*(M-T))
    break
  elif T+i[1] == M:
    print(P)
    break
  else:
    T=T+i[1]
    P=P+i[0]*i[1]

Submission status: Wrong Answer

Solution code:
nm, left = map(int, input().split())
shops = []
for _ in range(nm):
    shops.append([int(x) for x in input().split()])
shops.sort(key=lambda x: x[0])
#print(shops)
total_cost = 0
for cost, stock in shops:
    if stock >= left:
        print("final : " + str(total_cost + cost * left))
        exit(0)
    else:
        left = left - stock
        total_cost += cost * stock
        #print("current : " + str(total_cost))

Submission status: Wrong Answer

Solution code:
nm, left = map(int, input().split())
shops = []
for _ in range(nm):
    shops.append([int(x) for x in input().split()])
shops.sort(key=lambda x: x[0])
total_cost = 0
for cost, stock in shops:
    if stock >= left:
        print(total_cost + cost * left)
    else:
        left = left - stock
        total_cost += cost * stock

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(N):
  AB.append([int(i) for i in input().split()])

AB = sorted(AB,key=lambda x:x[1])

count = 0
ans = 0

for A,B in AB:
  if count + B > M:
    ans += A*(M-count)
    break
  else:
    ans += A*B
    count += B


print(ans)

Submission status: Wrong Answer

Solution code:
#C-Energy Drink Collector
#break文を使わないで攻略したい
N, M = map(int, input().split())
lst = []
for i in range(N):
    lst.append([j for j in map(int, input().split())])
#値段が安い順番に並べ直す
lst = sorted(lst)
#最小必要経費
cost = 0
#持っているドリンクの本数
drink = 0
#店の個数だけまわる予定
for i in range(N):
    if (drink + lst[i][1]) <= M:
        drink += lst[i][1]
        cost += lst[i][0] * lst[i][1]
    else:
        cost += lst[i][0] * (M - drink)
print(cost)

Submission status: Wrong Answer

Solution code:
#C-Energy Drink Collector
#break文を使わないで攻略したい
N, M = map(int, input().split())
lst = []
for i in range(N):
    lst.append([j for j in map(int, input().split())])
#値段が安い順番に並べ直す
lst = sorted(lst)
#最小必要経費
cost = 0
#持っているドリンクの本数
drink = 0
#店の個数だけまわる予定
for i in range(N):
    if (drink + lst[i][1]) <= M:
        drink += lst[i][1]
        cost =+ lst[i][0] * lst[i][1]
    else:
        cost += lst[i][0] * (M - drink)
        drink += (M - drink)
print(cost)

Submission status: Wrong Answer

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


for i in range(N):
    a , b = map(int,input().split())
    dict_sample.update({a:b})



money = 0
M_count = 0
for i in sorted(dict_sample.keys()):
    if M == M_count:
        break
    for z in range(dict_sample[i]):
        M_count += 1
        money += float(i)
        if M == M_count:
            break

print(money)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
from operator import itemgetter
input = sys.stdin.readline
N, M = map(int, input().split())

A = deque()
for i in range(N):
    A.append(list(map(int, input().split())))

A = sorted(A, key=itemgetter(1))

m=0
cost=0

for i in range(N):
    if m >= M:
        break
    buy = min(M - m, A[i][1])
    cost += A[i][0] * buy
    m += buy

print(cost)