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: Runtime Error

Solution code:
N, M = map(int, input().split())
dic = {}
for i in range(N):
    A, B = map(int, input().split())
    if A in dic.keys():
        dic[A] += B
    else:
        dic[A] = B
dic = sorted(dic.items())
price = 0
number = 0
for key in dic:
    if number + dic[key] < M:
        number += dic[key]
        price += dic[key] * key
    else:
        price += (M - number) * key
        break
print(price)

Submission status: Runtime Error

Solution code:
import operator

def get_mincost(M_left, cost, i):
    cost += sorted_d[i][0] * min(sorted_d[i][1], M_left)
    M_left -= min(sorted_d[i][1], M_left)
    i += 1
    if M_left == 0:
        return cost
    return get_mincost(M_left, cost, i)

N, M = map(int, input().split())
M_left = M
cost = 0
i = 0

#dict {A_i(price), B_i(num)}
d = dict(map(int, input().split()) for i in range(N))
global sorted_d
sorted_d = sorted(d.items(), key=operator.itemgetter(0))

print(int(get_mincost(M_left, cost, i)))

Submission status: Runtime Error

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 <=s 0:
        ans += k*m
        print(ans)
        exit()

    m = m-v

print(ans)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
x=[list(map(int,input().split())) for i in range(n)]
x.sort(key=lambda x: x[0])
#print(x)
num=0
money=0
i=0
if len(x)!=1:
    while num<=m:
        num+=x[i][1]
        money+=x[i][1]*x[i][0]
        i+=1
    #print(num)
    if num>m:
        i-=1
        money-=x[i][0]*(num-m)
    print(money)
else:
    print(x[0][0]*m)

Submission status: Runtime Error

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=sorted(AB)
i=0
amount=0
cost=0
while True:
  if amount+AB[i][1]<=m:
    amount+=AB[i][1]
    cost+=AB[i][0]*AB[i][1]
    i+=1
  else:
    cost+=(m-amount)*AB[i][0]
    print(cost)
    break

Submission status: Runtime Error

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

Submission status: Runtime Error

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 (N) :
    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: Runtime Error

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 (N) :
    M -= Xb[i][1]
    ans += Xb[i][0]*Xb[i][1]
    if M < 0 :
        ans -= abs(M)*Xb[i][0]
        break
    elif M == 0 :
        break
print(ans)

Submission status: Runtime Error

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 (N) :
    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: Runtime Error

Solution code:
n,m=map(int,input().split())
a_b=[list(map(int,input().split()))for i in range(n)]
#print(a_b)
#print(index(4))
honsuu=0
money=0
index=0
a=[]
for i in range(n):
    a.append(a_b[i][0])
c=sorted(a)
if len(c)>=2:
	while honsuu<=m:
		money+=a_b[a.index(c[index])][0]*a_b[a.index(c[index])][1]
		honsuu+=a_b[a.index(c[index])][1]
		index+=1
	index-=1
	honsuu-=a_b[a.index(c[index])][1]
	money-=a_b[a.index(c[index])][0]*a_b[a.index(c[index])][1]
	M=m-honsuu
	money+=a_b[a.index(c[index])][0]*M
#print(a_b[a.index(c[0])][1])
#print(index)
	print(money)
else:
	print(a_b[0][0]*a_b[0][1])

Submission status: Runtime Error

Solution code:
#C - Energy Drink Collector(ABC121)
N,M=map(int, input().split())
L={}
for i in range(N):
    A,B=map(int, input().split())
    L[A]=B
X=sorted(L.keys())
i=0
ans=0
while True:
    if M>=L[X[i]]:
        M-=L[X[i]]
        ans+=X[i]*L[X[i]]
        i+=1
        if M==0:
            break
    else:
        ans+=X[i]*M
        break
print(ans)

Submission status: Runtime Error

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

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

for i in range(n):
  if m >= d[i][1]:
    ans += d[i][0] * d[i][1]
    m -= d[i][1]
  else:
    ans += d[i][0] * m
    break
print(ans)

Submission status: Runtime Error

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

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

for i in range(n):
  if m >= d[i][1]:
    ans += d[i][0] * d[i][1]
    m -= d[i][1]
  else:
    ans += d[i][0] * m
    break
print(ans)

Submission status: Runtime Error

Solution code:
def find_AC(S):
  ret = []
  for i in range(len(S)-1):
    if S[i] == 'A' and S[i+1] == 'C':
      ret.append(i)
  return ret

N, Q = [int(x) for x in input().split()]
S = input()
result = find_AC(S)
print(result)
pos = [res+1 for res in result]

for _ in range(Q):
  l, r = [int(x) for x in input().split()]
  ans = 0
  for p in pos:
    if p>=l and p<=r-1:
      ans += 1
  print(ans)

Submission status: Runtime Error

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

res = M
n = 0
cnt = 0

if N == 1:
    cnt = res * AB[0][1]
else:
    while(AB[n][1] <= res):
        cnt += AB[n][0] * AB[n][1]
        res -= AB[n][1]
        n += 1

    cnt += res * AB[n][0]

print(cnt)

Submission status: Runtime Error

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: Runtime Error

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

# for i in range(N):
#     a, b = map(int, input().split())
#     p_list.append([a, b])
    
# p_sort = sorted(p_list, key=lambda x:x[0])
# num = 0
# price = 0
# i = 0
# while num < M:
#     num += p_sort[1][i]
#     price += p_sort[1][i] * p_sort[0][i]
#     if num > M:
#         price -= (num - M) * p_sort[0][i]
#     i += 1
# print(price)
res = M
for i in range(N):
    a, b = map(int, input().split())
    p_list.append(a, b)

for price, amount in sorted(zip(p_list[::2], p_list[1::2])):
    total_p += price * min(res, amount)
    res -= amount
    if res <= 0:
        break
        
print(total_p)

Submission status: Runtime Error

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

for i in range(N):
    a, b = map(int, input().split())
    p_list.append([a, b])
    
p_sort = sorted(p_list, key=lambda x:x[0])
num = 0
price = 0
i = 0
while num < M:
    num += p_sort[1][i]
    price += p_sort[1][i] * p_sort[0][i]
    if num > M:
      price -= (num - M) * p_sort[0][i]
    i += 1
print(price)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N,M = [int(s) for s in input().split()]
pre_lst=[]
for i in range(N):
  a,b = [int(s) for s in input().split()]
  pre_lst=lst+[[a,b,a*b]]
lst = sorted(pre_lst, key=lambda x: x[0])
m=0
i=0
cost=0
while(m<M):
  m+=lst[i][1]
  cost+=lst[i][2]
  i+=1
if(m>M):
  cost-=lst[i-1][0]*(m-M)
print(cost)

Submission status: Runtime Error

Solution code:
N,M = [int(s) for s in input().split()]
pre_lst=[]
for i in range(N):
  a,b = [int(s) for s in input().split()]
  pre_lst=lst+[[a,b,a*b]]
lst = sorted(pre_lst, lambda=x: x[0])
m=0
i=0
cost=0
while(m<M):
  m+=lst[i][1]
  cost+=lst[i][2]
  i+=1
if(m>M):
  cost-=lst[i-1][0]*(m-M)
print(cost)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
d={}
for i in range(n):
  a,b=map(int,input().split())
  d[b]=a
D=sorted(d.items(),key=lambda x:x[1])
val=0
cnt=0
j=0
while cnt<=m:
  cnt+=int(D[j][0])
  val+=int(D[j][1])
  j+=1
val-=int(D[j][1])*(cnt-m)
print(val)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
d={}
for i in range(n):
  a,b=map(int,input().split())
  d[b]=a
D=sorted(d.items())
val=0
cnt=0
j=0
while cnt<=m:
  cnt+=int(D[j][0])
  val+=int(D[j][1])
  j+=1
val-=int(D[j][1])*(cnt-m)
print(val)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
d={}
for i in range(n):
  a,b=map(int,input().split())
  d[b]=a
D=sorted(d.items())
val=0
cnt=0
j=0
while cnt<=m:
  cnt+=D[j][0]
  val+=D[j][1]
  j+=1
val-=D[j][1]*(cnt-m)
print(val)

Submission status: Runtime Error

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

a, b = map(int, input().split())

A.append(a)
B.append(b)

if N != 1:
    for n in range(N-1):
        a, b = map(int, input().split())
        swi = 0
        BSum = 0
        for j in range(len(A)):
            if BSum > M:
                swi = 1
                break
            else:
                if A[j] > a:
                    A.insert(j, a)
                    B.insert(j, b)
                    swi = 1
                    break
                elif A[j] == a:
                    B[j] += b
                    swi = 1
                    break
            BSum += b
        if swi == 0:
            A.append(a)
            B.append(b)

cntSum = 0
moneySum = 0

print(A, B)

for n in range(N):
    if cntSum + B[n] > M:
        moneySum += A[n] * (M - cntSum)
        cntSum += M - cntSum
        break
    else:
        cntSum += B[n]
        moneySum += A[n] * B[n]

print(moneySum)

Submission status: Runtime Error

Solution code:
import numpy as np
import collections
from collections import OrderedDict

n, m = map(int, input().split())
a = [0]*n
b = [0]*n
stores = collections.OrderedDict()
for i in range(n):
    a[i], b[i] = map(int, input().split())
    stores[a[i]] = b[i]

a_sorted = np.sort(np.array(a))

count = 0
cost = 0
i = 0

while count < m:
    a_min = a_sorted[i]
    while stores[a_min] > 0:
        count += 1
        cost += a_min
        stores[a_min] -= 1
        if count == m:
            break
    i += 1
    
print(cost)

Submission status: Runtime Error

Solution code:
import numpy as np
import collections
from collections import OrderedDict

n, m = map(int, input().split)
a = []*n
b = []*n
stores = collections.OrderedDict()
for i in range(n):
    a[i]= int(input())
    b[i]= int(input())
    stores[a[i]] = b[i]

a_sorted = np.sort(np.array(a))[0]

count = 0
cost = 0
i = 0

while count < m:
    a_min = a_sorted[i]
    while stores[a_min] > 0:
        count += 1
        cost += a_min
        stores[a_min] -= 1
    i += 1
    
print(cost)

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
AB=[[int(x) for x in input().split()] for i in range(N)]
AB.sort(key=lambda x: x[0])
out = 0
count = M
for i in range(M):
    if AB[i][1]<count+1:
        count-=AB[i][1]
        out+=AB[i][0]*AB[i][1]
    else:
        out+=count*AB[i][0]
        break
print(out)

Submission status: Runtime Error

Solution code:
import numpy as np
N, M= map(int, input().split(" "))
yen, hon = map(int, input().split(" "))
df = np.array([yen, hon]).T
for i in range(N-1):
  yen, hon = map(int, input().split(" "))
  df = np.vstack((df, [yen, hon]))
  
df = df[np.argsort(df[:, 0])] 

def func():
  m = 0
  cost = 0

  for i in range(len(df[:,1])):
    if (m + df[i, 1]) <= M:
      cost += df[i, 0] * df[i, 1]
      m    += df[i, 1]
    else:
      cost += df[i, 0] * (M - m)
      return cost

print(func())

Submission status: Runtime Error

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

ab = [[int(x) for x in input().split()] for _ in range(n)]

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

temp = sum(ab, [])  # 疑似Flatten
a, b = temp[0::2], temp[1::2]

count, index, remainder = 0, 0, 0

for bottle in b:
  index += 1
  if count + bottle < m:  
    count += bottle
  else:
    remainder = m - count
    break
    
total = a[index] * remainder
total += sum([a[i] * b[i] for i in range(index)])


print(total)

Submission status: Runtime Error

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: Runtime Error

Solution code:
n,m=map(int,input().split())
a=[]
for i in range(0,n):
    b,c=map(int,input().split())
    a.append([b,c])
a.sort()
number=0
for i in range(0,len(a)):
    while number<m:
        number=number+a[i][1]
        l=i
print(l)
answer=0
kosu=0
for k in range(0,l+1):
    answer=answer+a[k][0]*a[k][1]
    kosu=kosu+a[k][1]
print(answer)
answer=answer+a[l+1][0]*(m-kosu)
print(answer)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
a=[]
for i in range(0,n):
  b,c=map(int.input().split())
  a.append[b,c]
a.sort()
number=0
for i in range(0,len(a)):
  while number<m:
    number=number+a[i][1]
    l=i
answer=0
kosu=0
for k in range(0,l-1):
  answer=answer+a[k][0]*a[k][1]
  kosu=kosu+a[k][1]
answer=answer+a[l][0]*(m-kosu)
print(answer)

Submission status: Runtime Error

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

Submission status: Runtime Error

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: Runtime Error

Solution code:
from sys import stdin
import numpy as np
n, m = map(int, raw_input().split())
# print(n)
vals_list = np.zeros((n, 2))
# print(vals_list)
for itr in range(n):
    a, b = map(int, raw_input().split())
    vals_list[itr][0], vals_list[itr][1] = a, b
sorted_vals_list = vals_list[np.argsort(vals_list[:, 0])]
# print(sorted_vals_list)

cnt = m
total_money = 0
for itr in range(n):
    if (cnt - sorted_vals_list[itr][1]) <= 0:
        total_money += sorted_vals_list[itr][0] * cnt
        break
    else:
        cnt -= sorted_vals_list[itr][1]
        total_money += sorted_vals_list[itr][0] * sorted_vals_list[itr][1]
print(total_money)

Submission status: Runtime Error

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

import numpy as np

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

ablist=np.array([list(map(int,input().split())) for i in range(n)])

#aの昇順にソート
newablist=ablist[ablist[:,0].argsort(),:]
x=newablist


costcount=0
i=0

while x[i][1]<= m:
	m -= x[i][1]
	costcount += x[i][0]*x[i][1]
	i += 1

costcount += m*x[i][0]


print(costcount)

Submission status: Runtime Error

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

ans_min = lr[0][0]
ans_max = lr[0][1]

for i in range(m - 1):
    t = i + 1
    if lr[t][0] > lr[t - 1][0]:
        ans_min = lr[t][0]
    if lr[t][1] < lr[t - 1][1]:
        ans_max = lr[t][1]

print(ans_max - ans_min + 1)

Submission status: Runtime Error

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

ans = 0
res = M
for v in X:
    ans += v[0] * min(v[1], res)
    res -= v[1]
    if res <= 0:
        break
        
print(res)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
*storeList = map(int, open().read().split())
ans = 0
for a, b in sorted(zip(storeList[::2], storeList[1::2])):
    ans += a * min(m, b) ; m = max(0, m - b)
print(ans)

Submission status: Runtime Error

Solution code:
s=0;n,m=map(int,input().split())
d=dict([int(i) for i in input().split()] for j in range(n))
while True:
    print('d :', d)
    print('m :', m, '/ s :', s)
    mn=min(d.keys())
    if m-d[mn]<=0:
        s+=mn*m
        break
    else:
        m-=d[mn]
        s+=mn*d[mn]
        del d[mn]
print(s)

Submission status: Runtime Error

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

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

amt = 0
money = 0
i=0
while amt<=M:
    money+=List[i][0]*List[i][1]
    amt+=List[i][1]
    i+=1
    
ans = money-(amt-M)*List[i-1][0]
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**5)

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

def dfs(m,cnt):
    if m <= 0 or cnt == len(list):
        return 0
    b = list[cnt][1] if list[cnt][1] < m else m
    a = b*list[cnt][0]

    return a + dfs(m-b,cnt+1)

print(dfs(M,0))

Submission status: Runtime Error

Solution code:
from operator import itemgetter
n,m=map(int,input().split())
l=[]
for i in range(n):
  a,b=map(int,input().split)
  l.append([a,b])
l.sort(key=itemgetter(0))
s=0
for j in range(n):
  s=s+l[j][0]*min(l[j][1],m)
  m=m-l[j][1]
  if m<0:
    break
print(s)

Submission status: Runtime Error

Solution code:
from operator import itemgetter
n,m=map(int,input().split())
l=[]
for i in range(n):
  a,b=map(int,input().split)
  l.append([a,b])
l.sort(key=itemgetter(0))
s=0
for j in range(n):
  s=s+l[j][0]*min(l[j][1],m)
  m=m-l[j][1]
  if m<0:
    break
return s

Submission status: Runtime Error

Solution code:
for n in range(N):
    if sum(oB[:(n+1)])>=M:
        if n>0:
            print(oAs[n-1]+(oB[n]-sum(oB[:(n+1)])+M)*A[orderA[n]])
        else:
            print((oB[n]-sum(oB[:(n+1)])+M)*A[orderA[n]])
        exit()

Submission status: Runtime Error

Solution code:
n, m = map(int,input().split())
drink = []
for i in range(n):
  drink.append(list(map(int,input().split())))
sorteddrink = sorted(drink, key = lambda x:x[0])

count = 0
cost = 0
index = 0

while True:
  if index > n - 1:
    break
  if count + sorteddrink[index][1] > m:
    break
  cost += sorteddrink[index][0] * sorteddrink[index][1]
  count += sorteddrink[index][1]
  index += 1

cost += sorteddrink[index][0] * (m - count)
print(cost)

Submission status: Runtime Error

Solution code:
n, m = map(int,input().split())
drink = []
for i in range(n):
  drink.append(list(map(int,input().split())))
sorteddrink = sorted(drink, key = lambda x:x[0])

count = 0
cost = 0
index = 0

while True:
  if count + sorteddrink[index][1] > m:
    break
  cost += sorteddrink[index][0] * sorteddrink[index][1]
  count += sorteddrink[index][1]
  index += 1
  
cost += sorteddrink[index][0] * (m - count)
print(cost)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split(" "))
stores = dict()
p = 10000000000

for i in range(N):
    if p==1 and stores[p] >= M:
      break
    Ai, Bi = map(int, input().split(" "))
    if Ai in stores:
        stores[Ai] += Bi
    else:
        stores[Ai] = Bi
    p = min(p, Ai)


price = 0
for i, c in sorted(stores, key=lambda x: x[0]):
    if M <= c:
        price += i * M
        break
    else:
        price += i * c
        M -= c

print(price)

Submission status: Runtime Error

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

lst = []

for i in range(N):
    val = tuple(map(int,input().split()))
    lst.append(val)

A = []
for i in range(N.length):
    A.append(lst[i-1][0])

val = 0
while M > 0:
    res = A.index(min(A))
    if M - lst[res][1] > 0:
        val += lst[res][0]*lst[res][1]
        M = M - lst[res][1]
        lst.pop(res)
    else:
        val += lst[res][0]*M
        break

print(val)

Submission status: Runtime Error

Solution code:
N,m = list(map(int,input().split()))
data = {}
for i in range(N):
	a,b = list(map(int,input().split()))
	data[a] = b
sortedData = sorted(data.items())
cost = 0
for i in range(N):
	prices = sortedData[i][0]
	nums = sortedData[i][1]
	if m > nums:
		cost += prices * nums
		m -= nums
	else:
		cost += prices * m
		print(cost)
		break

Submission status: Runtime Error

Solution code:
N,m = list(map(int,input().split()))
data = {}
for i in range(N):
	a,b = list(map(int,input().split()))
	data[a] = b
sortedData = sorted(data.items())
cost = 0
for i in range(N):
	prices = sortedData[i][0]
	nums = sortedData[i][1]
	if m > nums:
		cost += price * nums
		m -= nums
	else:
		cost += prices * m
		print(cost)
		break

Submission status: Runtime Error

Solution code:
N,m = list(map(int,input().split()))
data = {}
for i in range(N):
	a,b = list(map(int,input().split()))
	data[a] = b
sortedData = sorted(data.items())
cost = 0
for i in range(N):
	v = sortedData[i][1]
	if m > v:
		cost += sortedData[i][0] * v
		m -= v
	else:
		cost += sortedData[i][0] * m
		print(cost)
		break

Submission status: Runtime Error

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

money = 0
count = 0

for a, b in V:
  if count + b < M:
    count += b
    money += a * b
  else:
    money += (M - b) * a
    break
print(money)

Submission status: Runtime Error

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())
match = 0
ans = 0
mini = min(a)

for j in range(n):
    for k in range(b[a.index(mini)]):
        if m <= match:
            break
        ans += mini
        match += 1
    
    b.pop(a.index(mini))
    a.remove(mini)
    mini = min(a)
print(ans)

Submission status: Runtime Error

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

for j in min(a):
    for k in range(b[a.index(j)]):
        if m <= match:
            break
        ans += j
        match += 1
    
    b.pop(a.index(j))
    a.remove(j)
print(ans)

Submission status: Runtime Error

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())
match = 0
ans = 0
mini = 0

while 1:
    mini = min(a)
    
    for j in range(b[a.index(mini)]):
        ans += mini
        match += 1
        if m == match:
            break
    
    a.remove(mini)
print(ans)

Submission status: Runtime Error

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

def dfs(m,cnt):
    if cnt >= len(list):
        return 0
    b = list[cnt][1] if list[cnt][1] < m else m
    a = b*list[cnt][0]
    if m - b < 0 :
        return 0

    return a + dfs(m-b,cnt+1)

print(dfs(M,0))

Submission status: Runtime Error

Solution code:
from math import ceil
N,M = map(int,input().split())
list = [list(map(int,input().split())) for i in range(N)]
list.sort(key=lambda x:x[0])

def dfs(m,cnt):
    if m <= 0 or cnt == len(list):
        return 0
    b = list[cnt][1] if list[cnt][1] < m else m
    a = b*list[cnt][0]

    return a + dfs(m-b,cnt+1)

print(dfs(M,0))

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
A,B = [],[]
for i in range(N):
  a,b = map(int,input().split())
  A += [a]
  B += [b]
AA = []
BB = []
while True:
  if len(A) == 0:
    break
  else:
    for i in range(len(A)):
      if A[i] == min(A):
        AA += [A[i]]
        BB += [B[i]]
        del A[i]
        del B[i]
rest = M
cost = 0
while True:
  if rest - BB[0] <= 0:
    cost += rest * AA[0]
    break
  else:
    rest -= BB[0]
    cost += AA[0] * BB[0]
    del AA[0]
    del BB[0]
print(cost)

Submission status: Runtime Error

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())
def merge(rr):
    mid=len(rr[0])
    c=int(mid/2)
    if mid>1:
        left=merge([rr[0][:c],rr[1][:c]])
        right=merge([rr[0][c:],rr[1][c:]])
        ar=[]
        br=[]
        while len(left[0])!=0 and len(right[0])!=0:
            if left[0][0]<right[0][0]:
                ar.append(left[0].pop(0))
                br.append(left[1].pop(0))
            else:
                ar.append(right[0].pop(0))
                br.append(right[1].pop(0))
        if len(left[0])!=0:
            ar.extend(left[0])
            br.extend(left[1])
        elif len(right[0])!=0:
            ar.extend(right[0])
            br.extend(right[1])
        rr=[ar,br]
    return rr
rr=[a,b]
re=merge(rr)
tot=0
sum=0
while(1):
    if tot+re[1][0]<=m:
        tot+=re[1][0]
        sum+=re[0][0]*re[1][0]
        re[1].pop(0)
        re[0].pop(0)
        if len(re[1])==0:
            break
    else:
        break
sum+=re[0][0]*(m-tot)
print(sum)

Submission status: Runtime Error

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())
def merge(rr):
    mid=len(rr[0])
    c=int(mid/2)
    if mid>1:
        left=merge([rr[0][:c],rr[1][:c]])
        right=merge([rr[0][c:],rr[1][c:]])
        ar=[]
        br=[]
        while len(left[0])!=0 and len(right[0])!=0:
            if left[0][0]<right[0][0]:
                ar.append(left[0].pop(0))
                br.append(left[1].pop(0))
            else:
                ar.append(right[0].pop(0))
                br.append(right[1].pop(0))
        if len(left[0])!=0:
            ar.extend(left[0])
            br.extend(left[1])
        elif len(right[0])!=0:
            ar.extend(right[0])
            br.extend(right[1])
        rr=[ar,br]
    return rr
rr=[a,b]
re=merge(rr)
tot=0
sum=0
while(1):
    if tot+re[1][0]<=m:
        tot+=re[1][0]
        sum+=re[0][0]*re[1][0]
        re[1].pop(0)
        re[0].pop(0)
    else:
        break
sum+=re[0][0]*(m-tot)
print(sum)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
A_B = []
for i in range(N):
    A_B.append(list(map(int, input().split())))
A_B.sort()
sum = 0
money = 0
i = 0
while sum <= M:
    money += A_B[i][0] * A_B[i][1]
    sum += A_B[i][1]
    i += 1
money -= A_B[i-1][0] * (sum - M)
print(money)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
A_B = []
for i in range(N):
    A_B.append(list(map(int, input().split())))
A_B.sort()
print(A_B)
sum = 0
money = 0
i = 0
while sum <= M:
    money += A_B[i][0] * A_B[i][1]
    sum += A_B[i][1]
    print(sum)
    i += 1
money -= A_B[i-1][0] * (sum - M)
print(money)

Submission status: Runtime Error

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

for i in range(N):
    a,b = map(int,input().rstrip().split())
    A.append(a)
    B.append(b)
D = dict(zip(A,B))
qed = 0
honsuu = D[min(D)]
sum = 0
if D[min(D)] >= M:
    sum = sum + min(D) * M
    print(sum)

else:
    sum = sum + min(D) * D[min(D)]
    del D[min(D)]
    while honsuu < M and qed == 0:
        if honsuu + D[min(D)] >= M:
             sum = sum + min(D) * (M - honsuu)
             print(sum)
             qed = 1
        else:
            honsuu = honsuu + D[min(D)]
            sum = sum + min(D) * D[min(D)]
            del D[min(D)]

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
store=[map(int,input().split()) for _ in range(N)]
store.sort(key=lambda x: x[0])
res=0
for i in range(len(store)):
  price=store[i][0]
  num=store[i][1]
  if M>num:
    res+=price*num
    M-=num
  else:
    res+=price*M
    break
print(res)

Submission status: Runtime Error

Solution code:
from sys import stdin

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

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

A_list = list(AB.keys())
A_list.sort()

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

Submission status: Runtime Error

Solution code:
from sys import stdin

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

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

A_list = list(AB.keys())
A_list.sort()

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