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: Accepted

Solution code:
class struct:
  def __init__(self,a,b):
    self.a=a
    self.b=b
n,m=map(int,input().split())
l=[]
for i in range(n):
  a,b=map(int,input().split())
  l.append(struct(a,b))
l=sorted(l,key=lambda x:x.a)
su=0
for x in l:
  if x.b<m:
    m-=x.b
    su+=(x.a)*(x.b)
  else:
    su+=(x.a)*m
    break
print(su)

Submission status: Accepted

Solution code:
N,M=[int(i) for i in input().split(" ")]
stores=[]
for j in range(N):
    A,B=[int(i) for i in input().split(" ")]
    stores.append([A,B])

stores=sorted(stores,key=lambda w:w[0])

money=0

while M>0:
    store=stores.pop(0)
    if store[1]>=M:
        money+=store[0]*M
        M=0
    else:
        money+=store[1]*store[0]
        M-=store[1]
print(money)

Submission status: Accepted

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

from operator import itemgetter
AB.sort(key=itemgetter(0))
ans = 0
n = M
for a, b in AB:
    if n - b > 0:
        ans += a * b
        n -= b
    else:
        ans += a * n
        break

print(ans)

Submission status: Accepted

Solution code:
if True:
    n,m=map(int,input().split())
    s=[(0,0) for i in range(n)]
    for i in range(n):
        s[i]=list(map(int,input().split()))
    #print(s)
else:
    n,m=2,5
    s=[(4,9),(2,4)]
s=sorted(s,key=lambda x: x[0])
#print(s)
d=0
ans=0
for i in range(n):
    pr=s[i][0]
    b=s[i][1]
    if d+b<m:
        ans+=pr*b
        d+=b
    else:
        ans+=(m-d)*pr
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(100000)
import heapq
input=lambda : sys.stdin.readline().rstrip('\n')

n,m=map(int,input().split())
data=[]
for i in range(n):
    a,b=map(int,input().split())
    heapq.heappush(data,(a,b))
cnt=0
cost=0
while True:
    a,b=heapq.heappop(data)
    if cnt+b>=m:
        cost+=(m-cnt)*a
        break
    else:
        cnt+=b
        cost+=a*b
print(cost)

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
L = [list(map(int,input().split())) for k in range(N)]
L = sorted(L)
ans = 0

for k in range(N):
    if M >= L[k][1]:
        ans += L[k][0]*L[k][1]
        M -= L[k][1]
        if M == 0:
            print(ans)
            exit(0)
    elif M < L[k][1]:
        ans += L[k][0]*M
        print(ans)
        exit(0)

Submission status: Accepted

Solution code:
n, m = map(int,input().split())
A = [list(map(int,input().split())) for i in range(n)]
ans = 0
A.sort(key=lambda x:x[0])

#print(A)
i = 0
while m>0 :
    ans += min(m,A[i][1])*A[i][0]
    m -= A[i][1]
    i += 1
    #print(ans)

print(ans)

Submission status: Accepted

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

import itertools
import collections
import bisect

def main():
    N, M = map(int, input().split())
    AB = []
    for _ in range(N):
        a, b = map(int, input().split())
        AB.append((a, b))
    AB.sort(key=lambda x:x[0])
    # print(AB)

    ans = 0
    rest = M

    for ab in AB:
        buy_count = min(rest, ab[1])
        ans += ab[0] * buy_count
        rest -= buy_count
        if rest == 0:
            break
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

c = 0
bought = 0
for a, b in sorted(abl, key=lambda x: x[0]):
  if bought + b < m:
    c += a * b
    bought += b
  else:
    c += a * (m - bought)
    break
print(c)

Submission status: Accepted

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

m = 0
c = 0
for x in X:
    c += x[0]*min(M-m, x[1])
    m += min(M-m, x[1])
    if m == M:
        break
print(c)

Submission status: Accepted

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

count = 0
cost = 0
for a, b in lst:
    if count + b > M:
        cost += a * (M - count)
        break
    count += b
    cost += a * b
print(cost)

Submission status: Accepted

Solution code:

if __name__ == "__main__":
    N, M = [int(i) for  i in input().split()]
    shops = []
    for i in range(N):
        shops.append([int(i) for i in input().split()])
    shops = sorted(shops)
    result = 0
    for price, stock in shops:
        if stock >= M:
            result += price * M
            break
        elif stock < M:
            result += price * stock
            M -= stock
    print(result)

Submission status: Accepted

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

e = list(sorted(e, key=lambda x: x[0]))
# 安値から

cost = 0
cnt = M
e_i = 0
while cnt > 0:
    can_buy = min(cnt, e[e_i][1])
    # 必要本数か売っている本数のうち少ない方

    cost += can_buy * e[e_i][0]
    e[e_i][1] -= can_buy
    cnt -= can_buy
    if e[e_i][1] == 0:
        e_i += 1

print(cost)

Submission status: Accepted

Solution code:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

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

AB.sort()

ans = 0
for a,b in AB:
    if M == 0:
        break
    if M > b:
        ans += a*b
        M -= b
    else:
        ans += a*M
        M -= M

print(ans)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
N,M=map(int,input().split())
drink=[tuple(map(int,input().split())) for _ in range(N)]
drink.sort(key=lambda x:x[0],reverse=True)
cost=0
cnt=0
while True:
    A,B=drink.pop()
    if cnt+B>=M:
        cost+=A*(M-cnt)
        break
    else:
        cnt+=B
        cost+=A*B
print(cost)

Submission status: Accepted

Solution code:

n,m =map(int,input().split())
lis = [[int(i)for i in input().split()]for _ in range(n)]
lis =sorted(lis,key=lambda x:x[0])
kane = 0
num = 0
for li in lis:
    if num + li[1] < m:
        kane += li[0]*li[1]
        num += li[1]
    else:
        kane += li[0]*(m-num)
        break
print(kane)

Submission status: Accepted

Solution code:
#!/usr/bin/env python2
"""
This file is part of https://github.com/cheran-senthil/PyRival
Copyright 2019 Cheran Senthilkumar <hello@cheran.io>

"""
from __future__ import division, print_function

import itertools
import os
import sys
from atexit import register
from io import BytesIO


class dict(dict):
    """ dict() -> new empty dictionary """

    def items(self):
        """ D.items() -> a set-like object providing a view on D's items """
        return dict.iteritems(self)

    def keys(self):
        """ D.keys() -> a set-like object providing a view on D's keys """
        return dict.iterkeys(self)

    def values(self):
        """ D.values() -> an object providing a view on D's values """
        return dict.itervalues(self)


def gcd(x, y):
    """ greatest common divisor of x and y """
    while y:
        x, y = y, x % y
    return x


range = xrange

filter = itertools.ifilter
map = itertools.imap
zip = itertools.izip

sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))

input = lambda: sys.stdin.readline().rstrip('\r\n')


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

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

    a.sort()
    cost = 0
    for ai in a:
        if ai[1] < m:
            cost += ai[1] * ai[0]
            m -= ai[1]
        else:
            cost += ai[0] * m
            break

    print(cost)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

ans = 0

for i in range(len(L)) :
    if L[i][1] < M :
        M -= L[i][1]
        ans += L[i][0]*L[i][1]
    else :
        ans += L[i][0]*M
        break
print(ans)

Submission status: Accepted

Solution code:
from operator import itemgetter

N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(N)]
money = 0
AB = sorted(AB, key=itemgetter(0,1))

for a, b in AB:
    n = min(M, b)
    money += a * n
    M -= n
    if M <= 0:
        break
print(money)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict


def main():
    N, M = [int(q) for q in input().split()]

    AB = [
        [int(q) for q in input().split()]
        for _ in range(N)
    ]
    AB = sorted(AB, key=lambda it: it[0])

    res = 0
    for ai, bi in AB:
        if bi >= M:
            res += ai * M
            print(res)
            return
        res += ai * bi
        M -= bi


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,m = li()
ab = []
for _ in range(n):
    ab.append(tuple(li()))
    
ab.sort()

rest = m
ans = 0
for a,b in ab:
    if rest > b:
        ans += a*b
        rest -= b
        
    elif rest == b:
        ans += a*b
        rest = 0
        
    else:
        ans += a*rest
        rest = 0
        
    if rest == 0:
        break
    
print(ans)

Submission status: Accepted

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

info = sorted(info)

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
lis = [list(map(int,input().split())) for i in range(n)]
lis.sort(key=lambda x:x[0])
ans = 0
cou = 0
num = 0
while cou < m:
    nu = min(lis[num][1], m - cou)
    cou += nu
    ans += lis[num][0] * nu
    num += 1
print(ans)

Submission status: Accepted

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

D.sort(key=lambda a: a[0])
ans = 0
num = 0
for price, n in D:
  if num + n >= M:
    ans += price * (M - num)
    break
  ans += price * n
  num += n
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())

n, m = mi()
a = [li() for i in range(n)]
a.sort(reverse=True)
rem = m
sm = 0
while a:
    rate, cnt = a.pop()
    take = min(rem, cnt)
    sm += take * rate
    rem -= take
print(sm)

Submission status: Accepted

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

Submission status: Accepted

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

AB = sorted(AB)

result = 0
c = 0
for a, b in AB:
    d = min(M - c, b)
    c += d
    result += d * a
    if c == M:
        break

print(result)

Submission status: Accepted

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

AB.sort()

res = 0
for a, b in AB:
    if M > b:
        M -= b
        res += a*b
    else:
        res += a*M
        break

print(res)

Submission status: Accepted

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

ABs.sort()

ans = 0
for A, B in ABs:
    ans += A * min(M, B)
    M -= min(M, B)
print(ans)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
X=[tuple(map(int,input().split())) for i in range(N)]
X.sort()
ans=0
tmp=0
for i in range(N):
    if tmp+X[i][1]>M:
        ans+=(M-tmp)*X[i][0]
        break
    ans+=X[i][0]*X[i][1]
    tmp+=X[i][1]
print(ans)

Submission status: Accepted

Solution code:
def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N, M = reads()
shop = []
for _ in range(N):
  A, B = reads()
  shop.append((A, B))
shop.sort(); shop.reverse()

count = 0
ans = 0
while count < M:
  A, B = shop.pop()
  m = min(M - count, B)
  count += m
  ans += m * A
print(ans)

Submission status: Accepted

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

ABL = sorted(ABL)

c = 0
for i in range(N):
	if M > ABL[i][1]:
		M -= ABL[i][1]
		c += ABL[i][0] * ABL[i][1]
	else:
		c += M * ABL[i][0]
		break

print(c)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import heapq
n, m = map(int, input().split())
que = []
for _ in range(n):
    a, b = map(int, input().split())
    heapq.heappush(que, (a, b))
answer = 0
while m > 0:
    a, b = heapq.heappop(que)
    answer += a * min(m, b)
    m -= b
print(answer)

Submission status: Accepted

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

Need = M
Payment = 0
for i in range(N):
    if Need > Drink[i][1]:
        Payment += Drink[i][0] * Drink[i][1]
        Need -= Drink[i][1]
    else:
        Payment += Drink[i][0] * Need
        break
print(Payment)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B
"""
n,m,c = LI()
b = LI()
a = LIR(n)
ans = 0
for i in range(n):
    d = c
    for k in range(m):
        d += b[k]*a[i][k]
    if d > 0:
        ans += 1
print(ans)
"""


#C
n,m = LI()
v = LIR(n)
v.sort(key = lambda x:x[0])
ans = 0
k = 0
for a,b in v:
    if k+b >= m:
        ans += (m-k)*a
        print(ans)
        quit()
    ans += b*a
    k += b
#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

res = 0
piv = 0
while m > 0:
    buy = min(m, drink[piv][1])
    res += buy * drink[piv][0]
    m -= buy
    piv += 1
print(res)

Submission status: Accepted

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

AB.sort()
Ans = 0
for i in AB:
  if i[1] >= M:
    Ans += i[0] * M
    break
  else:
    Ans += i[0] * i[1]
    M -= i[1]

print(Ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

n, m = map(int, input().split())
ab = defaultdict(int)
for _ in range(n):
    a, b = map(int, input().split())
    ab[a] += b

ans = 0
remain = m
for k in sorted(ab.keys()):
    if remain <= ab[k]:
        ans += k * remain
        break
    ans += k * ab[k]
    remain -= ab[k]
print(ans)

Submission status: Accepted

Solution code:
N,M = map(int, raw_input().split())
AB = [map(int, raw_input().split()) for _ in range(N)]
AB.sort()
ans = 0
for ab in AB:
  t = min(M, ab[1])
  ans += ab[0]*t
  M -= t
print ans

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
store = [tuple(map(int, input().split())) for _ in range(n)]
store.sort()
count = 0
cost = 0
for a, b in store:
    if m - count > b:
        count += b
        cost += a*b
    else:
        cost += (m - count) * a
        print(cost)
        exit()

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m = na()
ab = []
for i in range(n):
    ab.append(na())
ab.sort(key=lambda x: x[0])

rem = m
ans = 0
for v in ab:
    buy = min(rem, v[1])
    ans += buy * v[0]
    rem -= buy
print(ans)

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[A]=B
AB = sorted(AB.items(),key = lambda x:x[0])

acost = 0

for a,b in AB:
  cost += (min(max(M,0),b))*a
  M-=b
  if M<=0:
    break
print(cost)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
d = {}
cnt = 0
ans = 0
for i in range(n):
    a,b =map(int,input().split())
    d[a] = b
while cnt <m:
    if cnt+d[min(d)] <m:
        ans += min(d)*d[min(d)]
        cnt +=d[min(d)]
        del d[min(d)]
    else:
        ans += min(d)*(m-cnt)
        break
print(ans)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
stores = [tuple(map(int, input().split())) for _ in range(n)]
dict_stores = dict(stores)
lower_cost = sorted(dict_stores.keys())
total = 0
ans = 0
for i in range(n):
    total += dict_stores[lower_cost[i]]
    if total >= m:
        diff = m - (total - dict_stores[lower_cost[i]])
        ans += lower_cost[i] * diff
        break
    else:
        ans += lower_cost[i] * dict_stores[lower_cost[i]]
print(ans)

Submission status: Runtime Error

Solution code:
N, M = list(map(int, input().split()))
L = [tuple(map(int, input().split())) for i in range(N)]
L.sort()
# print(L)
ct = 0
cost = 0
i = 0
while ct < M:
    a = min(M-ct, L[i][1])
    ct += a
    cost += a*L[i][0]
    # print(ct,cost)
    i += 1
print(cos

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
list = []
for _ in range(n):
  a,b = map(int,input().split())
  list.append([a,b])
list.sort()
ans = 0
for a,b in l:
  ans += min(b,M)*a
  M = max(0,M-b)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
C = sorted(A)
while M > 0:

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

sum = 0
price = 0

A = list(C.keys())
A.sort()

for i in range(N):
    sum += C[A[i]]
    if sum >= M:
        sum -= C[A[i]]
        price += (M-sum)*A[i]
        break
    price += A[i]*C[A[i]]



print(price)

Submission status: Runtime Error

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

sum = 0
price = 0

while True:
    x = min(C.keys())
    C[x]
    sum += C[x]
    if sum >= M:
        sum -= C[x]
        break
    price += x*C[x]
    del C[x]

price += (M-sum)*x

print(price)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab.sort()
ans = 0
cnt = 0
i = 0
while cnt < m:
    ans += ab[i][0]*ab[i][1]
    cnt += ab[i][1]
    i += 1
print(num - (cnt - m)*ab[i][0])

Submission status: Runtime Error

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

import sys
sys.setrecursionlimit(200000000)
if n ==1:
    print(ca[0][0]*ca[0][1])
    sys.exit()
money = 0
i = 0
num = 0
while True:
    #print(str(i)+"だよ")
    if num + ca[i][1] <= m:
        num += ca[i][1]
        money += ca[i][0] * ca[i][1]
        i += 1
        #print(num,money)
    else:
        money += ca[i][0]*(m-num)
        break    
print(money)

Submission status: Runtime Error

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

import sys
if n ==1:
    print(ca[0][0]*ca[0][1])
    sys.exit()
money = 0
i = 0
num = 0
while True:
    #print(str(i)+"だよ")
    if num + ca[i][1] <= m:
        num += ca[i][1]
        money += ca[i][0] * ca[i][1]
        i += 1
        #print(num,money)
    else:
        money += ca[i][0]*(m-num)
        break    
print(money)

Submission status: Runtime Error

Solution code:
#python 2.7
n,m=map(int,input().split())
ab=[list(map(int,input().split()))]
ab=sorted(ab,key=lambda x:x[0])
res=ans=0
for i in range(n):
  if res+ab[i][1]>=m:
    ans+=(ab[i][0])*(m-res)
    break
  else:
    ans+=(ab[i][0])*ab[i][1]
    res+=ab[i][1]
print(ans)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
a_b = {}
for i in range(n):
    x,y = map(int,input().split())
    if x in a_b.keys():
        a_b[x] += y
        continue
    a_b[x] = y
a_b = sorted(a_b.items(), key=lambda x:x[0])

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

print(ans)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
a = []
b = []
for i in range(n):
    x,y = map(int,input().split())
    a.append(x)
    b.append(y)
if int(len(set(a))) == 1:
    print(a[0] * m)
    exit()
a_b = dict(zip(a,b))
a_b = sorted(a_b.items(), key=lambda x:x[0])

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

print(ans)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
a = []
b = []
for i in range(n):
    z,y = map(int,input().split())
    a.append(z)
    b.append(y)
a_b = dict(zip(a,b))
a_b = sorted(a_b.items(), key=lambda x:x[0])

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

print(ans)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
a = []
b = []
for i in range(n):
    x,y = map(int,input().split())
    a.append(x)
    b.append(y)
a_b = dict(zip(a,b))
a_b = sorted(a_b.items(), key=lambda x:x[0])

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

print(ans)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
ab=sorted([list(map(int,input().split())) for i in range(n)])
shop,cost,rest=m,0,0
while True:
    if ab[shop][1]<rest:
        cost+=ab[shop][1]*ab[shop][0]
        rest-=ab[shop][1]
        shop+=1
    else:
        cost+=ab[shop][0]*rest
        break
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.append([a,b])
 
d.sort(key=lambda x:x[0])

sum_ = 0
cnt = 0
for ab in d:
    if cnt + ab[1] > M:
        sum_ += ab[0] * (M-cnt)
        break
    else:
        cnt += ab[1]
        sum_ += ab[0]*ab[1]
print(sum_)

Submission status: Runtime Error

Solution code:
import numba
from numba import njit
i8 = numba.int64


@njit((i8, ), cache=True)
def main(n, m):

    A = []
    B = []
    cnt = 0
    ans = 0

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

    while cnt < m:
        A_min = min(A)
        A_min_index = A.index(A_min)
        if cnt + B[A_min_index] < m:
            ans += A_min * B[A_min_index]
            cnt += B[A_min_index]
            A.pop(A_min_index)
            B.pop(A_min_index)
        else:
            for i in range(B[A_min_index]):
                if cnt == m:
                    break
                ans += A_min
                cnt += 1

    print(ans)


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

main(n, m)

Submission status: Runtime Error

Solution code:
from numba import njit


@njit('void(i8)')
def main(n, m):

    A = []
    B = []
    cnt = 0
    ans = 0

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

    while cnt < m:
        A_min = min(A)
        A_min_index = A.index(A_min)
        if cnt + B[A_min_index] < m:
            ans += A_min * B[A_min_index]
            cnt += B[A_min_index]
            A.pop(A_min_index)
            B.pop(A_min_index)
        else:
            for i in range(B[A_min_index]):
                if cnt == m:
                    break
                ans += A_min
                cnt += 1

    print(ans)


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

main(n, m)