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:
n,m = map(int, input().split())
pairs = []
for _ in range(n):
    l = list(map(int,input().split()))
    pairs.append(l)
pairs.sort()
count = 0
ans = 0
for i in pairs:
    ans += i[0]*i[1]
    count += i[1]
    if count >= m:
        ans -= i[0]*(count - m)
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

stores.sort()
total = 0
i = 0
while True:
    if total >= M:
        i -= 1
        break
    total += stores[i][1]
    i += 1

ac = 0
k_count = 0
j = 0
while not j > i:
    if j == i:
        ac += stores[j][0] * (M-k_count)
    else:
        ac += stores[j][0] * stores[j][1]
    k_count += stores[j][1]
    j += 1

print(ac)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')
# ----------------------------------------------------------- #

n, m = Is()
AB = TIR(n)
AB.sort(key=itemgetter(0))
ans = 0
k = 0
for a, b in AB:
    if k+b < m:
        ans += a*b
        k += b
    else:
        ans += a*(m-k)
        print(ans)
        exit()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    ab = sorted(zip(A, B))
    k = 0
    ans = 0
    for Ai, Bi in ab:
        v = min(M - k, Bi)
        k += v
        ans += Ai * v
        if k >= M:
            break
    print(ans)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, A, B)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def main():
    N, M = map(int, input().split())
    drink = []
    for _ in range(N):
        a, b = map(int, input().split())
        drink.append((a, b))
    drink.sort(reverse=True)
    #print(drink)

    num = 0
    val = 0
    while num < M:
        a, b = drink.pop()
        if num + b <= M:
            num += b
            val += a * b
        else:
            val += a * (M - num)
            num = M
    print(val)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

from operator import itemgetter
ab = sorted(ab,key=itemgetter(0),reverse = False)

vl = 0
dr = 0

for i in range(n):
    if ab[i][1] + dr <= m:
        dr += ab[i][1]
        vl += ab[i][1] * ab[i][0]
    elif (ab[i][1] + dr > m) and dr < m :
        vl += (m-dr) * ab[i][0]
        dr += (m-dr)
        break
print(vl)

Submission status: Accepted

Solution code:
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    N,M=pin()
    A=sorted([lispin() for _ in range(N)])
    #print(A)
    ans=0
    for a in A:
        if a[1]>M:
            ans+=a[0]*M
            break
        else:
            ans+=a[0]*a[1]
            M-=a[1]
        #print(M)
    print(ans)
#%%submit!
resolve()

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

la = list()
lb = list()
for i in range(N):
    a, b = map(int, input().split())
    la.append(a)
    lb.append(b)

lab = list(zip(la, lb))
lab = sorted(lab, key=lambda x: x[0])

cst = 0
i = 0
while M - lab[i][1] > 0:
    M -= lab[i][1]
    cst += lab[i][0]*lab[i][1]
    i += 1

cst += lab[i][0] * M
print(cst)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,M = LI()
AB = sorted([LI() for _ in range(N)])
ans = 0
for A,B in AB:
    if M-B>=0:
        ans += A*B
        M -=B
    else:
        ans += A*M
        break
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n,m=MI()
lis=[LI() for i in range(n)]
lis.sort()
ans=0
rest=m
for i in range(n):
    ans+=lis[i][0]*min(lis[i][1],rest)
    rest-=min(lis[i][1],rest)
    if rest==0:
        break
print(ans)

Submission status: Accepted

Solution code:
import pprint
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in [0]*n]
ab.sort(key=lambda x: x[0])
ans = 0
cnt = 0
for i in range(n):
    a, b = ab[i]
    while b:
        if cnt==m: break
        ans += a
        cnt += 1
        b -= 1
print(ans)

Submission status: Accepted

Solution code:
from operator import itemgetter, attrgetter

n, m = list(map(int, input().split(' ')))
abn = [None] * n
for i in range(n):
    abn[i] = list(map(int, input().split(' ')))

abn = sorted(abn, key=itemgetter(0))

cost = 0
num = 0
for ab in abn:
    temp = 0
    while num < m and temp < ab[1]:
        cost += ab[0]
        temp += 1
        num += 1
    if num == m:
        break

print(cost)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
def main():
    N, M = list(map(int, input().split(' ')))
    shops = list()
    for _ in range(N):
        A, B = list(map(int, input().split(' ')))
        shops.append((A, B))
    shops.sort()
    drink = 0
    money = 0
    for s in shops:
        rest = M - drink
        cnt = min([rest, s[1]])
        drink += cnt
        money += cnt * s[0]
        if drink == M:
            break
    print(money)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())

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

    for i, j in ab:
        if m < j:
            ans += i*m
            break
        m -= j
        ans += i*j
        

    print(ans)

main()

Submission status: Accepted

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

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

    for i, j in ab:
        if m < j:
            ans += i*m
            break
        m -= j
        ans += i*j
        

    print(ans)

main()

Submission status: Accepted

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

    ab = [list(map(int, input().split())) for _ in range(n)]
    ab.sort()
    ans = 0

    for i, j in ab:
        if m < j:
            ans += i*m
            break
        m -= j
        ans += i*j
        

    print(ans)

main()

Submission status: Accepted

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

    ab = sorted([list(map(int, input().split())) for _ in range(n)])
    ans = 0

    for i, j in ab:
        if m >= j:
            m -= j
            ans += i*j
        elif m < j:
            ans += i*m
            break

    print(ans)

main()

Submission status: Accepted

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

ab = sorted([list(map(int, input().split())) for _ in range(n)])
ans = 0

for i, j in ab:
    if m >= j:
        m -= j
        ans += i*j
    elif m < j:
        ans += i*m
        break

print(ans)

Submission status: Accepted

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

s = []
for i in range(n):
    a,b = map(int,input().split())
    temp = (a,b)
    s.append(temp)
s.sort()

temp = 0
ans = 0
i = 0
while temp < m:
    p = min(s[i][1],m-temp)
    temp += p
    ans += (s[i][0])*p
    i += 1

print(ans)

Submission status: Accepted

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

count = 0
mount = 0
pair.sort(key=lambda x:x[0])
temp = 0
for i in range(n):
    mount += pair[i][0]*pair[i][1]
    count += pair[i][1]
    if(count >= m): 
        temp = i
        break

print(mount - (count - m)*pair[temp][0])

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
lis=[]
for i in range(n):
  lis.append(list(map(int,input().split())))
lis.sort()
counter=0
count=0
money=0
while count<m:
  kazu=min(m-count,lis[counter][1])
  money+=kazu*lis[counter][0]
  count+=kazu
  counter+=1
print(money)

Submission status: Accepted

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

AB.sort()
res=0
cnt=0

for a,b in AB:
	if cnt+b<m:
		cnt+=b
		res+=a*b
	else:
		res+=a*(m-cnt)
		break

print(res)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline

def main():
    N, M = map(int, readline().rstrip().split())
    AB = [tuple(map(int, readline().rstrip().split())) for _ in range(N)]
    AB.sort()
    pro = 0
    cost = 0
    for a, b in AB:
        if pro + b >= M:
            cost += (M - pro) * a
            break
        pro += b
        cost += a * b
    
    print(cost)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline

def main():
    N, M = map(int, readline().rstrip().split())
    AB = [list(map(int, readline().rstrip().split())) for _ in range(N)]
    AB.sort()
    pro = 0
    cost = 0
    for a, b in AB:
        if pro + b >= M:
            cost += (M - pro) * a
            break
        pro += b
        cost += a * b
    
    print(cost)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
abs = [list(map(int, input().split())) for _ in range(n)]
abs_sorted = sorted(abs, key=lambda x: x[0])
num = 0
ans = 0
while m != 0:
    a, b = abs_sorted[num][0], abs_sorted[num][1]
    if m >= b:
        ans += a * b
        m -= b
        num += 1
    else:
        ans += a * m
        m = 0
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

S=sorted(AB)
D=[]
check=0
ans=0
for i in range(N):
    check+=S[i][1]
    if check<=M:
        D+=[S[i][1]]
    else:
        b=check-M
        D+=[S[i][1]-b]
        break
for i in range(len(D)):
    ans+=D[i]*S[i][0]
print(ans)

Submission status: Accepted

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

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

ans=0
for c in cost_li:
    if m==0:
        break
    if m<c[1]:
        ans+=c[0]*m
        break
    ans+=c[0]*c[1]
    m-=c[1]
print(ans)

Submission status: Accepted

Solution code:
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
#N = I()
#A = [LI() for _ in range(N)]


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

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


def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    C = sorted(zip(A, B))
    ans = 0
    for a, b in C:
        if b >= M:
            return ans + a * M
        ans += a * b
        M -= b
    raise


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    print(solve(N, M, A, B))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()

Submission status: Accepted

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

a_b.sort()
sum_,all_ = m,0
for j in range(n):
  if sum_>=a_b[j][1]:
    sum_-=a_b[j][1]
    all_+=a_b[j][1]*a_b[j][0]
  elif sum_<a_b[j][1]:
    all_+=sum_*a_b[j][0]
    sum_-=sum_
print(all_)

Submission status: Accepted

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

Submission status: Accepted

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

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

ryoukin = 0
cnt = 0
for lst in d:
    for i in range(lst[1]):
        ryoukin += lst[0]
        cnt += 1
        if cnt == m:
            print(ryoukin)
            sys.exit()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest

def resolve():
    n, m = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in range(n)]

    ab = sorted(ab, key= lambda x:x[0])
    # print(ab)

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

    print(ans)

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """2 5
4 9
2 4"""
        output = """12"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """4 30
6 18
2 5
3 10
7 9"""
        output = """130"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """1 100000
1000000000 100000"""
        output = """100000000000000"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Accepted

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

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

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

print(ryoukin)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

money=0

for i in range(n):
    if m==0:
        break
    
    money+=l[i][0]*min(m, l[i][1])
    m-=min(m, l[i][1])


print(money)

Submission status: Accepted

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

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

money=0

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

    if m==0:
        break

print(money)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[0])
#print(ab)
money = 0
buy = 0

for i in range(n):
    if buy < m:
        money += ab[i][0]*min(ab[i][1], m-buy)
        buy += min(ab[i][1], m-buy)
    if buy == m:
        break
print(money)

Submission status: Accepted

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

Submission status: Accepted

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

for _ in range(N):
    Ai, Bi = map(int, input().split())
    AB.append((Ai, Bi))

AB = sorted(AB)
ans = 0
num = 0

for item in AB:
    if M - num >= item[1]:
        ans += item[0] * item[1]
        num += item[1]
    else:
        buy_num = M - num
        ans += item[0] * buy_num
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
##########
#import math
#import numpy as np
#import re
from operator import itemgetter #ex. sorted(l,key=itemgetter(0))
#from itertools import product as prod
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from collections import Counter as counter

ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(mi() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))
##########
def main(n,m,l):
    res = 0
    count = 0
    l = sorted(l,key=itemgetter(0))
    for a,b in l:
        if count + b < m:
            res += a * b
            count += b
            continue
        else:
            res += a * (m-count)
            count += (m-count)
    return res

n,m = mi()
l = mix(n)
print(main(n,m,l))

Submission status: Accepted

Solution code:
import numpy as np

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

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

print(coin)

Submission status: Accepted

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

Submission status: Accepted

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

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

ab.sort()
ans = 0
for i in range(n):
    if m <= 0:
        break
    ans += min(m, ab[i][1]) * ab[i][0]
    m -= ab[i][1]
print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
cnt = 0
L = []
for i in range(n):
    a,b = map(int,input().split())
    L.append([a,b])
L.sort()

cnt = 0
sum1 = 0
for i in range(n):
    price  = L[i][0]*L[i][1]
    num = L[i][1]
    if cnt + num <= m:
        cnt +=num
        sum1 +=price
    elif cnt + num > m:
        num = m - cnt
        sum1 += num*L[i][0]
        break
print(sum1)

Submission status: Accepted

Solution code:
# ABC121C

import numpy as np

n, m = map(int, input().split())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = list(map(int, input().split()))
a = np.array(a)
b = np.array(b)
c = np.argsort(a)
a = a[c]
b = b[c]
cost = 0
for i in range(len(a)):
    buy = min(b[i], m)
    cost += buy * a[i]
    # print(f"i = {i}  buy = {buy}  a[i] = {a[i]}")
    m -= buy
    if m == 0:
        break
print(cost)

Submission status: Accepted

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

AB.sort()

cnt=0
ans=0
for a,b in AB:

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
l = []
for i in range(n):
    l.append(list(map(int,input().split())))
l = sorted(l)
p = 0
d = 0
i = 0
while(d < m):
    s = min(l[i][1],m-d)
    d += s
    p += l[i][0] * s
    i += 1
print(p)

Submission status: Accepted

Solution code:
import numpy as np
N, M = map(int, input().split())
A = []
B = []
for _ in range(N):
  a, b = map(int, input().split())
  A.append(a)
  B.append(b)
cnt = 0
ans = 0
ind = np.argsort(A)
for i in range(N):
  m = min(M - cnt, B[ind[i]])
  ans += A[ind[i]] * m
  cnt += m
  if cnt >= M:
    break
print(ans)

Submission status: Accepted

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

for _ in range(n):
	ab.append(list(map(int,input().split())))

ab.sort()

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

Submission status: Accepted

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


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


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


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


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

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

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

print(ans)

Submission status: Accepted

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

money += AB[i][0]*M
M = 0
print(money)

Submission status: Accepted

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

ans = 0
for a, b in temp_list:
    ans += a * min(b, m)
    m -= b
    if m <= 0:
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
mylist=[]
for i in range(N):
    A,B=map(int,input().split())
    temp=[A,B]
    mylist.append(temp)
    
#print(mylist)

mylist.sort()
#print(mylist)

drink_sum=0
i=0
fee=0
while drink_sum<M and i<=N-1:
    if drink_sum+mylist[i][1]>=M:
        #print("/////")
        #print(drink_sum)
        #print(mylist[i][0]*(M-drink_sum))
        fee+=mylist[i][0]*(M-drink_sum)
        drink_sum+=M-drink_sum
        #print("before")
        #print(drink_sum)
    else:
        fee+=mylist[i][0]*mylist[i][1]
        drink_sum+=mylist[i][1]
        #print("test")
        #print(drink_sum)
        
    i+=1
    
print(fee)