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())
l=[]
for i in range(n):
  l.append(list(map(int, input().split())))
l = sorted(l, reverse=False)  
print(l)
def fns(hon, n, mon):
  if hon==m:
    return mon
  elif hon>m:
    return mon-(hon-m)*l[n-1][0]
  else:
    return fns(hon+l[n][1], n+1, mon+l[n][1]*l[n][0])
print(fns(0, 0, 0))

Submission status: Runtime Error

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

for i in range(n):
  l.append(list(map(int, input().split())))
l = sorted(l, reverse=False)  
def fns(hon, n, mon):
  if hon==m:
    return mon
  elif hon>m:
    return mon-(hon-m)*l[n-1][0]
  else:
    return fns(hon+l[n][1], n+1, mon+l[n][1]*l[n][0])
print(fns(0, 0, 0))

Submission status: Runtime Error

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

Submission status: Runtime Error

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


shop1=sorted(shop.items())

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:

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

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

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
a=[0]*n
b=[0]*n
ans=0
temp=0
for i in range(n):
  at,bt=map(int,input().split())
  a[i]=at
  b[i]=bt
import numpy as np
a=np.array(a)
b=np.array(b)
t=np.argmin(a)
while temp<m:
  ans=ans+a[t]
  temp=temp+1
  b[t]=b[t]-1
  if b[t]==0:
    a=np.delete(a,t)
    b=np.delete(b,t)
    t=np.argmin(a)
print(ans)

Submission status: Runtime Error

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

for i in range(N):
	a,b = map(int,input().split())
	if a in s.keys():
		s[a] += b
	else:
		s[a] = b

s = sorted(s.items(), key=lambda x:x[0])
for store in s:
	price = store[0]
	stock = store[1]
	if M == 0: break

	if M - stock >= 0:
		M -= stock
		ans += (stock * price)
	else:
		for i in range(stock):
			M -= 1
			ans += price
			if M == 0:
				print(ans)
				exit(1)
print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3

n, m = map(int, input().split())
a = [-1 for _ in range(n)]
b = [-1 for _ in range(n)]
d = {}
for i in range(n):
    a[i], b[i] = map(int, input().split())
    if a[i] not in d:
        d[a[i]] = b[i]
    else:
        d[a[i]] += b[i]

d = sorted(d.items(), key=lambda x:x[0])
num = ans = 0 
for i in range(n):
    tmp = num 
    num += d[i][1]
    if num <= m:
        ans += d[i][0]*d[i][1]
    else:
        ans += d[i][0]*(m-tmp)
        break

print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3

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

d = sorted(d.items(), key=lambda x:x[0])
num = ans = 0 
for i in range(n):
    tmp = num 
    num += d[i][1]
    if num <= m:
        ans += d[i][0]*d[i][1]
    else:
        ans += d[i][0]*(m-tmp)
#        import pdb; pdb.set_trace()
        break

print(ans)

Submission status: Runtime Error

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

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

d = sorted(d.items())

ans = 0

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

Submission status: Runtime Error

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

D={}
for i in range(N):
    D[A[i][0]]=A[i][1]
DD=sorted(D.items())
total=0
money=0
for i in range(N):
    if total+DD[i][1]<M:
        total+=DD[i][1]
        money+=DD[i][1]*DD[i][0]
    elif total+DD[i][1]>=M:
        money+=(M-total)*DD[i][0]
        break
print(str(money))

Submission status: Runtime Error

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

D={}
for i in range(N):
    D[A[i][0]]=A[i][1]
DD=sorted(D.items())
total=0
money=0
for i in range(N):
    if total+DD[i][1]<M:
        total+=DD[i][1]
        money+=DD[i][1]*DD[i][0]
    elif total+DD[i][1]>=M:
        money+=(M-total)*DD[i][0]
        print(str(money))
        break

Submission status: Runtime Error

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

D={}
for i in range(N):
    D[A[i][0]]=A[i][1]
DD=sorted(D.items())
total=0
money=0
for i in range(N):
    if total+DD[i][1]<M:
        total+=DD[i][1]
        money+=DD[i][1]*DD[i][0]
    elif total+DD[i][1]>=M:
        money+=(M-total)*DD[i][0]
        print(money)
        break

Submission status: Runtime Error

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

d={}

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

    if A in d:
        d[A]+=B
    else:
        d[A]=B

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

total=0
cnt=0

for i in range(n):
    total+=l[i][0]*l[i][1]

    cnt+=l[i][1]

    if cnt>m:
        total -= l[i][0]*(cnt-m)
        print(total)
        exit(0) 

print(total)

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[A]=B

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

total=0
cnt=0
for i in range(n):
    total+=l[i][0]*l[i][1]

    cnt+=l[i][1]

    if cnt>m:
        total -= l[i][0]*(cnt-m)
        print(total)
        exit(0) 

print(total)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
dict = {}
su = 0
kounyu = 0

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

d = sorted(dict.items())

for i in range(10**12):
  if d[i][1] >= m - kounyu:
    print(su + d[i][0]*(m - kounyu))
    exit()
    
  kounyu += d[i][1]
  su += d[i][1]*d[i][0]

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
dict = {}
sum = 0
kounyu = 0

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

d = sorted(dict.items())

for i in range(10**12):
  if d[i][1] >= m - kounyu:
    print(sum + d[i][0]*(m - kounyu))
    exit()
    
  kounyu += d[i][1]
  sum += d[i][1]*d[i][0]

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
dict = {}
sum = 0
kounyu = 0

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

d = sorted(dict.items())

for i in range(n):
  if d[i][1] >= m - kounyu:
    print(sum + d[i][0]*(m - kounyu))
    exit()
    
  kounyu += d[i][1]
  sum += d[i][1]*d[i][0]

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
from itertools import accumulate
N, M = map(int, input().split())
 
AB = []
 
for i in range(N):
    a, b = map(int, input().split())
    AB.append([a, b])

AB.sort(key=lambda x: x[0])
whole = [0]*sum([i[1] for i in AB])
cnt = 0
 
for ab in AB:
    for b in range(ab[1]):
        whole[cnt] = ab[0]
        cnt += 1

ans = list(accumulate(whole))

print(ans[M-1])

Submission status: Runtime Error

Solution code:
from itertools import accumulate
N, M = map(int, input().split())
 
AB = []
 
for i in range(N):
    a, b = map(int, input().split())
    AB.append([a, b])

AB.sort(key=lambda x: x[0])
whole = [None]*sum([i[1] for i in AB])
cnt = 0
 
for ab in AB:
    for b in range(ab[1]):
        whole[cnt] = ab[0]
        cnt += 1

ans = list(accumulate(whole))

print(ans[M-1])

Submission status: Runtime Error

Solution code:
import numpy as np
N, M = map(int, input().split())

AB = np.zeros([N, 2], dtype=int)

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

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

cnt = 0
whole = np.zeros(AB[:, 1].sum(), dtype=int)

for ab in AB:
    for b in range(ab[1]):
        whole[cnt] = ab[0]
        cnt += 1

whole = whole.cumsum()

print(int(whole[M-1]))

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
n,m=map(int,input().split())
shop=[]
for i in range(n):
    shop.append(map(int,input().split()))
shop_sorted=sorted(shop,key=lambda x :x[0])
ans=0
cnt=0
for a,b in shop_sorted:
    tmp=cnt
    cnt=min(m,cnt+b)
    ans+=a*(cnt-tmp)
    if cnt==m:
        break
print(ans)

Submission status: Runtime Error

Solution code:
n,m = map (int,input().split())
a = [0] * n
b = [0] * n
box = [0] * n
for i in range(n):
    a[i],b[i] = map(int,input().split())
    box[i] = [a[i],b[i]]
box.sort(key = lambda x:x[0])
s = 0
ans = 0
while m >= 0:
    m -= box[s][1]
    ans += box[s][0] * box[s][1]
    s += 1
    
print(ans - (-m) * box[s - 1][0])

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

AB.sort()

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

Submission status: Runtime Error

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

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

ab_hash = {}
count = 0
price_sum = 0
for x in ab:
    ab_hash[x[0]] = x[1]
ab_key_sorted = sorted(ab_hash.items(), key=lambda x: x[0])
while M > 0:
    if M > ab_key_sorted[count][1]:
        price_sum += ab_key_sorted[count][0] * ab_key_sorted[count][1]
    else:
        price_sum += ab_key_sorted[count][0] * M
    M = M - ab_key_sorted[count][1]
    count += 1

print(price_sum)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab = sorted(ab, key=lambda ab:ab[0])

ans = 0
total = 0
for i in range(n):
  num = m-toal
  if ab[i][1]<=num:
    total += ab[i][1]
    ans += ab[i][0]*ab[i][1]
  else:
    total += num
    ans += num*ab[i][1]
    break
print(ans)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split()）
ab = [list(map(int,input().split())) for _ in range(n)]
ab = sorted(ab, key=lambda ab:ab[0])

ans = 0
total = 0
for i in range(n):
  num = m-toal
  if ab[i][1]<=num:
    total += ab[i][1]
    ans += ab[i][0]*ab[i][1]
  else:
    total += num
    ans += num*ab[i][1]
    break
print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
from sys import stdin
import numpy as np
#import math
#from functools import reduce
    
N, M = [int(x) for x in stdin.readline().rstrip().split()]
#N = int(input())
#S = list(input())

costs = []
num = []

#is_exist = 'Yes'
for n in range(N):
    ai, bi = [int(x) for x in stdin.readline().rstrip().split()]
    costs += [ai]
    num += [bi]
    
sorted_idx = np.argsort(costs)
costs = list(np.array(costs)[sorted_idx])
num = list(np.array(num)[sorted_idx])

count_num = 0
count_cost = 0
for i, n in enumerate(num):
    if count_num + n < M:
        count_cost += n*costs[i]
        count_num += n
    else:
        count_cost += costs[i]*(M-count_num)
        break

print(count_cost)

Submission status: Runtime Error

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

Submission status: Runtime Error

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
#
j=0
mm=m
while mm>0:
	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
	j=j+1
	mm=mm-ArB[j]	
    
#print(ArA, ArB)
price = 0
i=0
while m>0:
	price = price + ArA[i] * min(m, ArB[i])
#	print(m, ArB[i],ArA[i])
	m = m - min(m, ArB[i])
	i = i+1
    
print(price)

Submission status: Runtime Error

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
#
j=0
mm = m
while mm >0:
	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
    mm=mm-ArB[j]
    j=j+1
		
    
#print(ArA, ArB)
price = 0
i=0
while m>0:
	price = price + ArA[i] * min(m, ArB[i])
#	print(m, ArB[i],ArA[i])
	m = m - min(m, ArB[i])
	i = i+1
    
print(price)

Submission status: Runtime Error

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
#
for j in range(m):
	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)
price = 0
i=0
while m>0:
	price = price + ArA[i] * min(m, ArB[i])
#	print(m, ArB[i],ArA[i])
	m = m - min(m, ArB[i])
	i = i+1
    
print(price)

Submission status: Runtime Error

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],b[i] = map(int,input().split())

bought = 0
ans = 0
while(bought <= m):
    remain = m - bought
    if b[a.index(min(a))] <= remain:
        ans += min(a)*b[a.index(min(a))]
        bought += b[a.index(min(a))]
        b.remove(b[a.index(min(a))])
        a.remove(min(a))
    else:
        ans += min(a)*remain
        break
print(ans)

Submission status: Runtime Error

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

ab_hash = {}
count = 0
price_sum = 0
for x in ab:
    ab_hash[x[0]] = x[1]
ab_key_sorted = sorted(ab_hash.items(), key=lambda x: x[0])
while M > 0:
    if M > ab_key_sorted[count][1]:
        price_sum += ab_key_sorted[count][0] * ab_key_sorted[count][1]
    else:
        price_sum += M * ab_key_sorted[count][0]
    M = M - ab_key_sorted[count][1]
    count += 1

print(price_sum)

Submission status: Runtime Error

Solution code:
# coding: utf-8
import os
from sys import stdin
from functools import total_ordering

__dirname = os.path.dirname(__file__)
__basename = os.path.splitext(os.path.basename(__file__))[0]
__targetname = './input/' + __basename + '.txt'
target_path = os.path.join(__dirname, __targetname)
stdin = open(target_path)

@total_ordering
class struct(object):
    def __init__(self,a,b):
        self.a=a
        self.b=b
    def __lt__	(self,other):
        return self.a < other.a
    def __eq__	(self,other):
        return self.a == other.a

def main():
    # st = struct(10,1)
    # print(st.a)
    input_line = stdin.readline().rstrip().split(' ')
    N, M = map(int, input_line)
    A = list()
    for _ in range(N):
        input_line = stdin.readline().rstrip().split(' ')
        a,b=map(int, input_line)
        st=struct(a,b)
        A.append(st)
    A.sort()
    ans=0
    time=0
    for x in A:
        # print(x.a,x.b)
        if(time>M):
            continue
        if((time+x.b)<=M):
            ans += x.a*x.b
            time += x.b
        else:
            ans += x.a*(M-time)
            time = M
    print(ans)



if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
shop=[]
for _ in range(N):
    a=list(map(int,input().split()))
    shop.append(a)
shop.sort(key=lambda x: x[0])
cnt=0
p=0
i=0

while cnt<=M:
    a=shop[i][0]
    b=shop[i][1]
    cnt+=b
    p+=a*b
    i+=1
su=cnt-M

a = shop[i-1][0]
p-=a*su
print(p)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

honsu=0
cost=0
for i in range(N):
  honsu+=data[i][1]
  cost+=data[i][0]*data[i][1]
 
  if honsu>M:
    ans=cost-((honsu-M)*data[i][0])
print(ans)

Submission status: Runtime Error

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

honsu=0
cost=0
for i in range(N):
  honsu+=data[i][1]
  cost+=data[i][0]*data[i][1]
 
  if honsu>M:
    ans=cost-((honsu-M)*data[i][0])
print(ans)

Submission status: Runtime Error

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

drink_list.sort(key=lambda x: x[0])
#print(drink_list)

_cnt=0
_sum=0
i=0
if N==1 or drink_list[i][1]>=M:
    _sum=drink_list[i][0]*M
else:
    while _cnt<M:
        if _cnt+drink_list[i][1]>M:
            break
        else:
            _sum+=drink_list[i][0]*drink_list[i][1]
            _cnt+=drink_list[i][1]
            i+=1
        #print(_sum,_cnt,i)
    _sum+=drink_list[i][0]*(M-_cnt)

print(_sum)

Submission status: Runtime Error

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

drink_list.sort(key=lambda x: x[0])
#print(drink_list)

_cnt=0
_sum=0
i=0
if N==1:
    _sum=drink_list[i][0]*M
else:
    while _cnt<M:
        if _cnt+drink_list[i][1]>M:
            break
        else:
            _sum+=drink_list[i][0]*drink_list[i][1]
            _cnt+=drink_list[i][1]
            i+=1
        #print(_sum,_cnt,i)
    _sum+=drink_list[i][0]*(M-_cnt)

print(_sum)

Submission status: Runtime Error

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

#  値段Aの昇順でソート
C = sorted(zip(A, B))
A, B = zip(*C)

ans, cnt, i = 0, 0, 0
while cnt < M:
	tmp = min(B[i], M - cnt)
	cnt += tmp
	ans += A[i] * tmp
	i += 1
print(ans)

Submission status: Runtime Error

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

data.sort()

price = 0
for d in data:
    price += d[0] * min(M, d[1])
    M -= d[1]
    if M <= 0:
        break
print(price)

Submission status: Runtime Error

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

key = sorted(list(dic))
count = sum(list(dic.values()))

money = 0
num = 0


for i in range(count):
    for i in range(dic[key[num]]):
        price = key[num]
        money += price
        M -= 1
        if M == 0:
            print(money)
            exit()
    num += 1

Submission status: Runtime Error

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

key = sorted(list(dic))

money = 0
num = 0

while True:
    for i in range(dic[key[num]]):
        price = key[num]
        money += price
        M -= 1
        if M == 0:
            print(money)
            exit()
    num += 1

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
a=[]
b=[]
for i in range(n):
    ai,bi=map(int,input().split())
    a.append(ai)
    b.append(bi)
    for ii in range(i-1):
        if ai<a[ii]:
            a.insert(ii)=ai
            b.insert(ii)=bi
            break
        else:
            a.append(ai)
            b.append(bi)
print(ai)

Submission status: Runtime Error

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

for _ in range(N):
    a, b = map(int, input().split())
    AB.setdefault(a, b)

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

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

print(ans)

Submission status: Runtime Error

Solution code:
n,k = map(int, input().split())
a = sorted([tuple(input().split()) for i in range(n)])
ans = 0
for x in a:
  temp = min(x[1],k)
  ans += temp*x[0]
  k = max(0,k-temp)
print(ans)

Submission status: Runtime Error

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

C = dict(zip(A,B))

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

ans = 0
cnt = 0

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

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
L=0
R=n
for i in range(m):
    l,r=map(int,input().split())
    if l>L:
        L=l
    if r<R:
        R=r
if R-L<0:
    print(0)
else:
    print(R-L)

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
2 3
1 32
2 63
1 12

Submission status: Runtime Error

Solution code:
M, N = map(int, input().split())
COST, STOCK = range(2)
energy_drinks = sorted((tuple(map(int, input().split())) for _ in range(N)), key=lambda tuple_: tuple_[COST])

cost = 0
for energy_drink in energy_drinks:
    buy = min(energy_drink[STOCK], N)
    N -= buy
    cost += buy * energy_drink[COST]
print(cost)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n, m = (int(i) for i in input().split())  
a = [[int(i) for i in input().split()] for i in range(n)] 
dic = {}
lis = []
 
for x in a:
  if x[0] not in dic:
  	dic[x[0]] = x[1]
  else:
    dic[x[0]] += x[1]

sorted_dict = sorted(dic.items(), key=lambda x:x[0])
 
count = 0
for x in sorted_dict:
  if len(lis) > m:
    break
  else:
    lis += [int(x[0])] * int(x[1])
    count += x[1]
  
#print(lis)
print(sum(lis[:m]))

Submission status: Runtime Error

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

for x in a:
  if x[0] not in dic:
  	dic[x[0]] = x[1]
  else:
    dic[x[0]] += x[1]

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

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

Submission status: Runtime Error

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

for x in a:
  if x[0] not in dic:
  	dic[x[0]] = x[1]
  else:
    dic[x[0]] += x[1]

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

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

Submission status: Runtime Error

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

for x in a:
  if x[0] not in dic:
  	dic[x[0]] = x[1]
  else:
    dic[x[0]] += x[1]

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

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

Submission status: Runtime Error

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

for x in a:
  if x[0] not in dic:
  	dic[x[0]] = x[1]
  else:
    dic[x[0]] += x[1]

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

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

Submission status: Runtime Error

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

for x in a:
  if x[0] not in dic:
  	dic[x[0]] = x[1]
  else:
    dic[x[0]] += x[1]

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

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

Submission status: Runtime Error

Solution code:
def main():
  n, m = map(int, input().split())
  shops = sorted([list(map(int, input().split())) for i in range(n)])
  
  cost = 0
  got = 0
  for shop in shops:
    if got + shop[1] <= m:
      got += shop[1]
      cost += shop[0] * shop[1]
    else:
      cost += (m - got) * shop[0]
      break
  print(cost)
  

if __init__ == '__main__':
  main()

Submission status: Runtime Error

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

for i in range(N):
    if num + store[i][1] < M:
        num + = store[i][1]
        price += store[i][0] * store[i][1]
    else:
        price += store[i][0]　* (M-num)
        break
print(price)

Submission status: Runtime Error

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

for i in range(N):
    if num + store[i][1] < M:
        num + = store[i][1]
        price += store[i][0] * store[i][1]
    else:
        price += store[i][0]　* (M-num)
        break
print(price)

Submission status: Runtime Error

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

for i in range(N):
    if num + store[i][1] < M
        num + = store[i][1]
        price += store[i][0] * store[i][1]
    else:
        price += store[i][0]　* (M-num)
        break
print(price)