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:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, M = LI()
    A = []
    for _ in range(N):
        a, b = LI()
        A.append((a, b))
    A = sorted(A, key=lambda x:x[0])
    bought = 0
    ix = 0
    money = 0
    while bought < M:
        if bought + A[ix][1] > M:
            money += A[ix][0] * (M - bought)
            break
        bought += A[ix][1]
        money += A[ix][0] * A[ix][1]
        ix += 1
    print(money)


main()

Submission status: Accepted

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

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

ans = 0
i = 0
mat.sort()
#値でsortする
while True:
    if m - mat[i][1] > 0:
        ans += mat[i][1]*mat[i][0]
        m -= mat[i][1]
        i += 1
    else:
        ans += mat[i][0] *m
        break
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
List = []
for _ in range(N):
  P, Q = map(int,input().split())
  List.append([P,Q])
List = sorted(List)
total = 0
for item in List:
  for _ in range(item[1]):
    total += item[0]
    M -= 1
    if M == 0:
      break
  if M == 0:
    break
print(total)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
ary = []
for _ in range(n):
    ary.append(list(map(int, input().split())))
ary.sort()

res = 0
for (a, b) in ary:
    if m-b>0:
        m -= b
        res += a*b
    else:
        res += a*m
        break
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(N)]
AB=sorted(AB, key=lambda a:a[0]  )
ans=0
l=0
for ab in AB:
  if l+ab[1]<=M:
    l+=ab[1]
    ans+=ab[0]*ab[1]
  else:
    for i in range(ab[1]):
      if l<M:
        l+=1
        ans+=ab[0]
  if l==M:
    print(ans);break

Submission status: Accepted

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

Submission status: Accepted

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*a
        break
print(ans)

Submission status: Accepted

Solution code:
M, N = map(int, input().split())
COST, STOCK = range(2)
energy_drinks = sorted((tuple(map(int, input().split())) for _ in range(M)), 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: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**7)
inf = float('inf')
mod = 10**9+7
ans = 0 ;count = 0 ;pro = 1


n,m=map(int,input().split())
AB=[tuple(map(int,input().split())) for i in range(n)]
AB.sort(key=lambda tup:tup[0])
i=0
while count<m:
    ans+=min(m-count,AB[i][1])*AB[i][0]
    count += min(m-count, AB[i][1])
    i+=1
print(ans)

Submission status: Accepted

Solution code:
from operator import itemgetter
N,M = map(int,input().split())
ls = [list(map(int,input().split())) for _ in range(N)]
ls = sorted(ls,key=itemgetter(0))
ans = 0
pon = 0
for i in range(N):
    if pon < M:
        pon += ls[i][1]
        ans += ls[i][1]*ls[i][0]
    else:
        i = i-1
        break
if pon == M:
    print(ans)
else:
    ans -= ls[i][0]*(pon - M)
    print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ab = []
for i in range(n):
    a = list(map(int, input().split()))
    ab += [a]
ab.sort(key=lambda x: x[0])
count = 0
sum_drink = 0
for i in range(n):
    for j in range(ab[i][1]):
        sum_drink += ab[i][0]
        count+=1
        if count >= m:
            print(sum_drink)
            exit()

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    N, M = map(int, input().split())
    *AB, = map(int, stdin.read().split())
    A = AB[::2]
    B = AB[1::2]
    num = 0
    yen = 0
    for a, b in sorted(zip(A, B)):
        if M < num + b:
            yen += a * (M - num)
            break
        else:
            yen += a * b
            num += b
    print(yen)
    return


main()

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    N, M = map(int, input().split())
    *AB, = map(int, stdin.read().split())
    A = AB[::2]
    B = AB[1::2]
    Z = zip(A, B)
    Z = sorted(Z)
    num = 0
    yen = 0
    for a, b in Z:
        if M < num + b:
            yen += a * (M - num)
            break
        else:
            yen += a * b
            num += b
    print(yen)
    return


main()

Submission status: Accepted

Solution code:
from sys import stdin

N, M = map(int, input().split())
*AB, = map(int, stdin.read().split())


def main():
    A = AB[::2]
    B = AB[1::2]
    Z = zip(A, B)
    Z = sorted(Z)
    num = 0
    yen = 0
    for a, b in Z:
        if M < num + b:
            yen += a * (M - num)
            break
        else:
            yen += a * b
            num += b
    print(yen)
    return


main()

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
array = []
suma = 0
summ = 0
for i in range(N):
    ab = list(map(int,input().split()))
    array.append(ab)
array.sort()

for i in range(N):
    if suma + array[i][1] <= M:
        suma += array[i][1]
        summ += array[i][1]*array[i][0]
    else:
        summ += (M-suma)*array[i][0]
        break
print(summ)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
x=[list(map(int,input().split())) for _ in range(n)]
x.sort()
p,c=0,0

for a,b in x:
  if c+b<=m:
    p+=a*b
    c+=b
  else:
    p+=a*(m-c)
    c+=m-c
    break
print(p)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
def solve(n, dst):
    xs = []
    ans_cost = 0

    for _ in range(n):
        c, q = map(int, input().split())
        xs.append((c, q))
    xs.sort()

    for cost, quant in xs:
        if quant >= dst:
            ans_cost += cost * dst
            return ans_cost
        else:
            dst -= quant
            ans_cost += cost * quant


if __name__ == '__main__':
    n, dst = map(int, input().split())
    print(solve(n, dst))

Submission status: Accepted

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

for i in range(m):
    if ab[ind][1] > 0:
        cnt += ab[ind][0]
        ab[ind][1] -= 1
    else:
        ind += 1
        cnt += ab[ind][0]
        ab[ind][1] -= 1
print(cnt)

Submission status: Accepted

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N, M = MAP()
SHOP = [MAP() for _ in range(N)]
SHOP.sort()

A = [s[0] for s in SHOP]
B = [s[1] for s in SHOP]

#print(A, B)

bought = 0
money = 0
for i in range(N):
	if bought+B[i] < M:
		money += A[i]*B[i]
		bought += B[i]
	else:
		money += A[i]*(M-bought)
		bought += M-bought

print(money)

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 a,b in ab:
    ans+=a*min(b,m)
    m-=b
    if m<=0:
        break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
L = []
for i in range(N):
    a,b = map(int,input().split())
    s = (a,b)
    L.append(s)
L.sort()
ans = 0
cnt = 0
for i,j in L:
    if(M> (cnt+ j)):
        ans += i * j
        cnt += j
    elif (M <= (cnt + j)):
        ans += i * (M - cnt)
        break
print(ans)

Submission status: Accepted

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

for n in range(N):
    a, b = map(int, input().split())
    C[n] = (a, b)

C.sort()
m = 0
res = 0

for c in C:
    buy = min(c[1], M-m)
    m += buy
    res += c[0] * buy
    if m == M:
        break

print(res)

Submission status: Accepted

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


print(ans)

Submission status: Accepted

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

a.sort()
ans = 0
for x in a:
  if x[1] >= m:
    ans += x[0] * m
    break
  else:
    ans += x[0] * x[1]
    m -= x[1]

print(ans)

Submission status: Accepted

Solution code:
from operator import itemgetter

n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]

num = sorted(a)
total = 0
ans = 0

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

Submission status: Accepted

Solution code:
from sys import stdin
import sys
N, M = [int(x) for x in stdin.readline().rstrip().split()]
A = []
for _ in range(N):
    temp = [int(x) for x in stdin.readline().rstrip().split()]
    A.append(temp)
A = sorted(A, key = lambda x: x[0])
ans = 0
for i in range(N):
    a = min(M, A[i][1])
    ans += a * A[i][0]
    M -= a
    if M == 0:
        print(ans)
        sys.exit()

Submission status: Accepted

Solution code:
import heapq

N, M = map(int, input().split())
A_B = []
for i in range(N):
    a, b = map(int, input().split())
    heapq.heappush(A_B, (a, b))

count = 0
price = 0
while count < M:
    a_b = heapq.heappop(A_B)
    count += a_b[1]
    price += a_b[1] * a_b[0]

print(price - (count-M)*a_b[0])

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def print_ans(N, M, arr):
    """Test Case
    >>> print_ans(2, 5, [[4, 9], [2, 4]])
    12
    >>> print_ans(4, 30, [[6, 18], [2, 5], [3, 10], [7, 9]])
    130
    >>> print_ans(1, 100000,[[1000000000, 100000]])
    100000000000000
    """
    ans = 0
    tmp = M
    arr = sorted(arr)
    for ar in arr:
        if tmp > ar[1]:
            ans += ar[0] * ar[1]
        else:
            ans += ar[0] * tmp
            break
        tmp -= ar[1]
    print(ans)


if __name__ == '__main__':
    N, M = map(int, input().rstrip().split())
    arr = [list(map(int, input().rstrip().split())) for _ in range(N)]
    print_ans(N, M, arr)

Submission status: Accepted

Solution code:
def main():
    n,m=map(int,input().split())
    ab=[]
    for _ in range(n):
        a,b=map(int,input().split())
        ab.append((a,b))
    ab=sorted(ab,key=lambda x: x[0])
    c=0
    for a,b in ab:
        if m>b:
            c+=a*b
            m-=b
        else:
            c+=a*m
            print(c)
            return
main()

Submission status: Accepted

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])
res=0
i=0
while True:
    if m==0:
        print(res)
        exit()
    if a[i][1]!=0:
        a[i][1]-=1
        res+=a[i][0]
        m-=1
    else:
        i+=1
        a[i][1]-=1
        res+=a[i][0]
        m-=1

Submission status: Accepted

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

ABn =[ list(map(int,input().split(' '))) for _ in range(N)]  
ABn.sort(key=lambda x:(x[0]))
amount_yen = 0
for i in range(N):
    if ABn[i][1] < M:
        M -= ABn[i][1]
        amount_yen += ABn[i][0] * ABn[i][1]
    else:
        amount_yen += ABn[i][0] * M
        break
print(amount_yen)

Submission status: Accepted

Solution code:
#ABC C121
import sys
n, m = map(int, sys.stdin.readline().split())
L = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]

L = sorted(L, key=lambda x:x[0])
total=0
for a, b in L:
    if m-b>=0:
        m-=b
        total+=a*b
        if m==0:
            print(total)
            break
    else:
        total +=a*m
        print(total)
        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.sort(key=lambda store: store[0])
price = 0
for i in range(n):
    price += L[i][0] * min(m, L[i][1])
    m -= min(m, L[i][1])
    if m <= 0:
      print(price)    
      exit()

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
X=[]
for i in range(N):
  a,b=map(int,input().split())
  X +=[[a,b]]
X.sort()
answer=0
i=0
while M>0:
  if X[i][1]<=M:
    answer +=X[i][0]*X[i][1]
  elif X[i][1]>M:
    answer +=M*X[i][0]
  M -=X[i][1]
  i+=1
print(answer)

Submission status: Accepted

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

dd=[]
for i in d:
      dd.append([i[0],i[1]])

ans=0
i=0
c=0
while m>c:
      if dd[i][1]!=0:
            dd[i][1]+=-1
            ans+=dd[i][0]
            c+=1
      else:
            i+=1
     
print(ans)

Submission status: Accepted

Solution code:
n, m = map(int,input().split())
l = sorted(list(map(int,input().split())) for i in range(n))
ans = 0
for i in range(n):
  if l[i][1] <= m:
    ans += l[i][0] * l[i][1]
    m -= l[i][1]
  elif m >= 0 and l[i][1] >= m:
    ans += l[i][0] * m
    break
print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
sorted_ab=sorted(ab, key=lambda x: x[0])
ans=0
i=0
for a, b in sorted_ab:
  for _ in range(b):
    if i < m:
      ans+=a
      i+=1
    else:
      break
print(ans)

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 a, b in ab:
        if m > b:
            m -= b
            ans += a*b

        else:
            print(ans+a*m)
            break


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

AB = sorted([list(map(int, input().split())) for i in range(N)])
ans = 0
idx = 0
while M:
    
    b = min(M, AB[idx][1])
    ans += AB[idx][0] * b
    M -= b
    idx += 1
    
print(ans)

Submission status: Accepted

Solution code:
n,m = (int(i) for i in input().split())
ab = []
for i in range(n) :
  a,b = input().split()
  ab.append((int(a),int(b)))
  
ab = sorted(ab,key=lambda i:i[0])



cost = 0
for i in range(n) :
  a,b = ab[i]
  c = m - b
  if 0 <= c :
    cost += a*b
    m -= b    

  else :
    cost += a*m
    m = 0    

  if m == 0 :
    print(cost)
    break

Submission status: Accepted

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 __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import heapq

h = []
n, m = list(map(int, input().split()))
for _ in range(n):
  a, b = list(map(int, input().split()))
  heapq.heappush(h, (a, b))

cost = 0
while True:
  (a, b) = heapq.heappop(h)
  if b < m:
    cost += a * b
    m -= b
  else:
    cost += a * m
    break

print(cost)

Submission status: Accepted

Solution code:
#20:15
n,m = map(int,input().split())
ab = []
for _ in range(n):
  ab.append(list(map(int,input().split())))
ab.sort()
ans = 0
for x in ab:
  a,b = x
  if m - b > 0:
    m -= b
    ans += a * b
  else:
    ans += a * m
    break
print(ans)

Submission status: Accepted

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

a,b = zip(*sorted(zip(a,b)))
ans = 0
cnt_drink = 0
pos = 0
while cnt_drink < m:
    if m - cnt_drink >= b[pos]:
        ans += b[pos]* a[pos]
        cnt_drink += b[pos]
    else: 
        ans += (m - cnt_drink) * a[pos]
        cnt_drink = m
    pos += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N,M=map(int,input().split(' '))
AB=[list(map(int,input().split(' '))) for _ in range(N)]

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

ans=0
m=0
for x in AB:
  if m+x[1]<M:
    ans+=x[0]*x[1]
    m+=x[1]
  else:
    ans+=x[0]*(M-m)
    break
print(ans)

Submission status: Accepted

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

while True:
    if m == 0:
        print(ans)
        quit()
    if li[0][1] == 0:
        li.pop(0)
    ans += li[0][0]
    li[0][1] -= 1
    m -= 1

Submission status: Accepted

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

cnt_mount=0
cnt_money=0

for i in range(M):
    cnt_money +=(list_aaa[i][0])*(list_aaa[i][1])
    cnt_mount +=list_aaa[i][1]
    if cnt_mount>=M:
        cnt_money -=(cnt_mount-M)*list_aaa[i][0]
        break
print(cnt_money)

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(key=lambda x:(x[0], x[1]))
ans = 0
for i in range(N):
   cost = AB[i][0]
   b = AB[i][1]
   if b < M:
      M -= b
      ans += b*cost
   else:
      ans += cost * M
      break
print(ans)

Submission status: Accepted

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

data = [[0,0] for _ in range(n)]
for i in range(n):
  data[i][0],data[i][1] = map(int, input().split())

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

rest = m
money = 0
for a,b in data:
  #print(a,b)
  if b <rest:
    rest-=b
    money+=a*b
  else:
    money += a*rest
    break

print(money)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

ans=0
for i in range(len(d)):
  a=d[i][0]
  b=d[i][1]
  if b<m:
    m-=b
    ans+=a*b
  else:
    ans+=a*m
    break
print(ans)

Submission status: Accepted

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

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

total = 0
for i in s:
    total+=i[0]*i[1]
    m-=i[1]
    if m <= 0:
        total+=i[0]*m
        break
        
print(total)

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

print(money)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
drink = [list(map(int,input().split())) for n in range(N)]
drink.sort(key=lambda x: x[0])
Cnt = 0
Ttl = 0
x = 0
while Cnt < M:
  while Cnt < M and drink[x][1] > 0:
    Cnt += 1
    Ttl += drink[x][0]
    drink[x][1] -= 1
  x += 1

print(Ttl)

Submission status: Accepted

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

Submission status: Accepted

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

#print(L)
#print(sorted(L))#第一要素でソート
L.sort()
for j in range(N):
    num = L[j][1]
    if M > num:
        money = L[j][0]*L[j][1]
        M -= num
        cost += money
    elif M == 0:
        break
    else:
        money = L[j][0]*M
        cost += money
        break
print(cost)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
import fractions
N,M=map(int,input().split())
AB=sorted([list(map(int,input().split())) for i in range(N)],key=lambda x:x[0])
hon=0
yen=0
abidx=0
while M>hon:
    hon,yen=min(M-hon,AB[abidx][1])+hon,AB[abidx][0]*min(M-hon,AB[abidx][1])+yen
    abidx+=1
print(yen)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#nは店の数、mは必要な栄養ドリンクの数
n,m=map(int,input().split())

#a円の栄養ドリンクがb本
ab=[]
for i in range(n):
    ab.append(list(map(int,input().split())))

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

print(cost)

Submission status: Accepted

Solution code:
from operator import itemgetter
def f(ab, cnt, price, n, m):
        for i in range(n):
                if cnt + ab[i][1] > m:
                        for j in range(1, ab[i][1]):
                                cnt += 1
                                if cnt == m:
                                        price += ab[i][0] * j
                                        break
                        # print(cnt)
                        # print(price)
                        # print("--------")
                        break
                else:
                        cnt += ab[i][1]
                        price += ab[i][0] * ab[i][1]
                        # print(cnt)
                        # print(price)
                        # print("--------")
        # if cnt < m:
        #         print("再帰")
        #         f(ab, cnt, price, n, m)
        # else:
        #         return price
        return price

n, m = map(int, input().split())
ab = []
for _ in range(n):
        ab.append(list(map(int, input().split())))
ab.sort()
# print(ab)
# print("*********")
cnt = 0
price = 0
# for i in range(n):
#         if cnt + ab[i][1] > m:
#                 print("if")
#                 for j in range(1, ab[i][1]):
#                         cnt += j
#                         if cnt == m:
#                                 price += ab[i][0] * j
#                                 break
#                 print(cnt)
#                 print(price)
#                 print("--------")
#                 break
#         else:
#                 cnt += ab[i][1]
#                 price += ab[i][0] * ab[i][1]
#                 print(cnt)
#                 print(price)
#                 print("--------")
print(f(ab, cnt, price, n, m))

Submission status: Accepted

Solution code:
storeNum, canNum = input().split()
storeNum = int(storeNum)
canNum = int(canNum)
costs = [0] * storeNum
maxCanNumbers = [0] * storeNum

for i in range(storeNum):
    costs[i], maxCanNumbers[i] = input().split()
    costs[i] = int(costs[i])
    maxCanNumbers[i] = int(maxCanNumbers[i])

currentStoreHasMoreCans = False
totalPrice = 0

costs, maxCanNumbers = (list(x) for x in zip(*sorted(zip(costs, maxCanNumbers))))

for i in range(storeNum):
    if canNum >= maxCanNumbers[i]:
        totalPrice = totalPrice + costs[i] * maxCanNumbers[i]
        canNum = canNum - maxCanNumbers[i]
        if canNum is 0:
            break
    else:
        totalPrice = totalPrice + costs[i] * canNum
        canNum = 0    
        break

print(totalPrice)

Submission status: Accepted

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

abl = []
for _ in range(n):
    a,b = map(int,input().split())
    abl.append((a,b))
    
abl = sorted(abl)

ans = 0
now = 0
for a,b in abl:
    need = m - now
    now += min(need, b)
    ans += min(need, b) * a
    if now == m:
        break
    
print(ans)

Submission status: Accepted

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