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 = [int(i) for i in input().split()]
li = [0]*N
for i in range(N):
    li[i] = [int(j) for j in input().split()]
li.sort()
ans = 0
for i in range(N):
    if M - li[i][1] > 0:
        M -= li[i][1]
        ans += li[i][0]*li[i][1]
    else:
        ans += li[i][0]*M
        print(ans)
        exit()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


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

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

    for a, b in AB:
        if M - b >= 0:
            result += a * b
        else:
            result += a * M
            break
        M -= b
    print(result)


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

ab.sort()

ans = 0
drink = 0
i = 0

while drink < M:
    if ab[i][1] == 0:
        i += 1

    ans += ab[i][0]
    ab[i][1] -= 1
    drink += 1

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())
    #n店舗、a値段、b本数
    s.append([a,b])
s.sort()
ans=0
i=0
while m-s[i][1]>0:
    m-=s[i][1]
    ans+=s[i][0]*s[i][1] #値段
    i+=1
print(ans+s[i][0]*m)

Submission status: Accepted

Solution code:
#abc121 c
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
for yen,kosu in ab:
    if m==0:
        break
    x=min(kosu,m)
    m-=x
    ans+=yen*x
print(ans)

Submission status: Accepted

Solution code:


def submit():
    n, m = map(int, input().split())
    price_stocks = [tuple(map(int, input().split())) for _ in range(n)]
    price_stocks.sort(key=lambda x: x[0])

    pay = 0
    for price, stock in price_stocks:
        if stock < m:
            m -= stock
            pay += price * stock
        else:
            pay += price * m
            break

    print(pay)
            

if __name__ == "__main__":
    submit()

Submission status: Accepted

Solution code:

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

data = []

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

data.sort(key = lambda x: x[0])
buy = 0
ans = 0
for i in range(n):
    buy = min(data[i][1], m)
    ans += buy * data[i][0]
    m -= buy
    if m == 0:
        break


print(ans)

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:
    if cnt+b >= M:
        break
    cnt += b
    ans += a*b
ans += a*(M-cnt)
print(ans)

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

cost, num, want = 0, M, M
for i in range(N):
  num = min(want, AB[i][1])
  cost += AB[i][0] * num
  want -= num
  if num == 0:
    break
print(cost)

Submission status: Accepted

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

drink = []
for i in range(n):
  a, b = map(int, input().split())
  drink.append((a,b))
drink.sort(key=lambda x: x[0])
ans = 0
for ai in drink:
  ans += ai[0] * min(ai[1], m)
  m -= ai[1]
  if m <= 0:
    print(ans)
    break

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = [0]*N
for i in range(N):
  A[i] = [0,0]
  A[i][0],A[i][1] = map(int, input().split())
A.sort()
sum = 0
for a in A:
  if a[1]<M:
    sum += a[0]*a[1]
    M -= a[1]
  else:
    sum += a[0]*M
    print(sum)
    exit()

Submission status: Accepted

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

i = 0 # 今何本かったか
price = 0 # 合計いくらか
for a, b in ab:
    price += a * min(b, m-i)
    i += min(b, m-i)
    if i == m:
        print(price)
        exit()

Submission status: Accepted

Solution code:
x, y= map(int, input().split())
s=[list(map(int,list(input().split()))) for i in range(x)]
k= list(s)
k.sort()
a=0
t=0
for i in range(x):
	if y-a>=k[i][1]:
		t=t+k[i][0]*k[i][1]
		a=a+k[i][1]
	else:
		t=t+((y-a)*k[i][0])
		a=y
print(t)

Submission status: Accepted

Solution code:
from collections import deque
def solve():
    N, M = map(int, input().split())
    data = []
    for i in range(N):
        a, b = map(int, input().split())
        data.append((a, b))
    
    data.sort(key=lambda x: x[0])
    data = deque(data)

    ans = 0
    cnt = 0
    while cnt < M:
        d = data.popleft()
        for i in range(d[1]):
            cnt += 1 
            ans += d[0]
            if cnt >= M:
                break
    
    print(ans)
        

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N,M=map(int,input().split())

shop=[]

for _ in range(N):
    A,B=map(int,input().split())
    shop.append([A,B])

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

ans=0
for money, num in shop:
    if M<=num:
        ans+=money*M
        break
    else:
        ans+=money*num
        M-=num

print(ans)

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 cost: cost[0])

ans = 0
count = 0
for v in a:
  ans += v[0] * v[1]
  count += v[1]
  if count > m:
    while True:
      count -= 1
      ans -= v[0]
      if count == m:
        break
  if count == m:
    break

print(ans)

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

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

Submission status: Accepted

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

P.sort()

ans = 0
buy = 0
for i in range(N) :
    if buy + P[i][1] >= M :
        ans += (M-buy) * P[i][0]
        print(ans)
        exit()
    else :
        ans += P[i][0] * P[i][1]
        buy += P[i][1]

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n, m = map(int, input().split())
  ABs = []
  for _ in range(n):
    A, B = map(int, input().split())
    ABs.append((A, B))
  ABs.sort(key= lambda x:x[0])
  payment = 0
  num = 0
  for A, B in ABs:
    payment += A*B
    num += B
    if num >= m:
      print(payment - A * (num - m))
      break
    
    
  
if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
from operator import itemgetter
N, M = map(int, input().split())
C = []*N
for i in range(N):
    x, y = map(int, input().split())
    C.append((x,y))
C.sort(key=itemgetter(0))

res = 0
for i,j in C:
    if M==0:
        break
    if M > j:
        res += i*j
        M -= j
    else:# M <= j
        res += i*M
        M -= M
print(res)

Submission status: Accepted

Solution code:
def main():
  import sys
  input = sys.stdin.readline
  n,m=map(int,input().split())
  ab=[list(map(int,input().split())) for _ in [0]*n]
  ab=sorted(ab,key=lambda x:x[0])
  ans=0
  for i in range(n):
    l=min(ab[i][1],m)
    m-=l
    ans+=l*ab[i][0]
    if l==0:
      print(ans)
      exit()
  print(ans)
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.sort()

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

print(cost)

Submission status: Accepted

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

drink.sort()
i = price = 0
remaining = m
while remaining > 0:
    a, b = drink[i]
    if remaining >= b:
        price += a * b
    else:
        price += a * remaining
    remaining -= b
    i += 1

print(price)

Submission status: Accepted

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

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

#print(l)
money=0
count=0
for i in range(n):
    a=l[i][0];b=l[i][1]
    if (m-count)>b :
        count+=b
        money+=a*b
    else:
        money+=a*(m-count)
        count+=(m-count)
        break
print(money)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ab=[]
for i in range(n):
	lst=list(map(int,input().split()))
	ab.append(lst)
ab.sort()
cost=0
now=0
while m!=0:
	cost+=ab[now][0]
	ab[now][1]-=1
	m-=1
	if ab[now][1]==0:
		now+=1
print(cost)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# coding: utf-8

(n,m) = map(int, input().rstrip().split(" "))
shop_list = list(sorted([[int(i) for i in input().rstrip().split(" ")] for j in range(n)]))

remain = m
ans = 0

for i in shop_list:
    if remain == 0:
        break
    tmp = min(remain, i[1])
    ans += i[0] * tmp
    remain -= tmp

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(key=lambda x:x[0])
ans=0
for i in range(n):
  d=min(ab[i][1],m)
  m-=d
  ans+=ab[i][0]*d
  if m==0:
    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())
  S.append([a, b])

S.sort(key=lambda x: x[0])
price = 0
count = 0
for s in S:
  if count + s[1] < M:
    price += s[0] * s[1]
    count += s[1]
  else:
    price += s[0] * (M - count)
    break

print(price)

Submission status: Accepted

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

Submission status: Accepted

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

total_price = 0
drink_num  = 0


for i in range(N):
    drink_num += drink_store[i][1]
    if M <= drink_num:
        left = drink_num - M
        total_price += (drink_store[i][0]*drink_store[i][1]) - (drink_store[i][0]*left)
        break
    else:
         total_price += drink_store[i][0]*drink_store[i][1]

print(total_price)

Submission status: Accepted

Solution code:
# import bisect
# from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, m = list(map(int,ipti().split()))
    ab = [[0] * 2 for _ in range(n)]
    for i in range(n):
        ab[i] = list(map(int,ipti().split()))

    ab.sort(key=itemgetter(0))
    ans = 0

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

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(cost)

Submission status: Accepted

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

ab.sort()
num = 0
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[]
for _ in range(n):
    a.append([int(i) for i in input().split()])
a.sort()
ans=0 ; ind=-1 ; p=0
while ans<m:
    ind+=1
    ans+=a[ind][1]
for i in range(ind):
     p+=a[i][1]*a[i][0]
p+=a[ind][0]*(a[ind][1]-(ans-m))
print(p)

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
n,m=map(int,input().split())
a=[]
for _ in range(n):
    a.append([int(i) for i in input().split()])
a.sort()
ans=0 ; ind=-1 ; p=0
while ans<m:
    ind+=1
    ans+=a[ind][1]
for i in range(ind):
     p+=a[i][1]*a[i][0]
p+=a[ind][0]*(a[ind][1]-(ans-m))
print(p)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ans = 0
drink_num = 0
# 値段に関してソート
ab.sort(key=lambda shop: shop[0])
for i in range(n):
    if (drink_num + ab[i][1]) > m:
        ans += ab[i][0] * (m - drink_num)
        drink_num += m - drink_num
        break
    ans += ab[i][0] * ab[i][1]
    drink_num += ab[i][1]
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()
onedan = 0
for ab in AB:
    buy = min(ab[1], M)
    onedan += buy * ab[0]
    M -= buy
print(onedan)

Submission status: Accepted

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

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

i,ans,cnt = 0,0,0

while cnt < m:
    ans += sorted_ab[i][0]*min(m-cnt,sorted_ab[i][1])
    cnt += min(m-cnt,sorted_ab[i][1])
    i+=1
print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

AB.sort(key=lambda x:x[0],reverse=False)

t=0
cnt=0
while M>0:
    A = AB[t][0]
    B = AB[t][1]
    if M>B:
        M = M-B
        cnt+=A*B
        t+=1
    else:
        cnt += A*M
        M = 0

print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    #from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #r = input()
    #n = int(input())
    #a, b = map(int, input().split())
    #s, y = input().split()
    #a = input().split()
    #a = [int(input()) for i in range(n)]
    #a = list(map(int, input().split()))
    #a = [list(map(int, input().split())) for i in range(n)]
    #a = [int(s) - 1 for s in input().split()]
    #l=[int(input()) for _ in range(int(input()))]
    #res = 0
    n,m = map(int,input().split())
    a = [list(map(int, input().split())) for i in range(n)]
    a.sort(key=lambda x:x[0])

    res = 0
    for i in a:
        mm = min(m,i[1])
        res += i[0]*mm
        m -= mm
        if m <= 0:
            break
    print(res)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

cnt = 0
ans = 0

i = 0
while cnt < M:
    ans += store[i][0]
    cnt += 1
    store[i][1] -= 1

    if store[i][1] == 0:
        i += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
d = [list(map(int, input().split())) for _ in range(N)]
ans = 0
d.sort()
for i in d:
    if i[1] <= M:
        ans += i[0] * i[1]
        M -= i[1]
        if M == 0:
            break
    else:
        ans += 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)]
ab.sort(key=lambda x: x[0])

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

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()
d_count = 0
money = 0
j = 0

for i in range(M):
    if d_count == AB[j][1]:
        d_count = 0
        j += 1

    money += AB[j][0]
    d_count += 1
    
print(money)

Submission status: Accepted

Solution code:
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])

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
ab = sorted(ab, key=lambda x: x[0])
#print(ab)
ans = 0
for a, b in ab:
    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())
cost = []
for i in range(n):
    a,b = map(int,input().split())
    cost.append([a,b])
cost.sort()
cnt = 0
price = 0
for i in range(n):
    if cnt + cost[i][1] <= m:
        price += cost[i][0] * cost[i][1]
        cnt += cost[i][1]
    else:
        price += (m-cnt)*cost[i][0]
        print(price)
        exit()
print(price)

Submission status: Accepted

Solution code:
#energy drink collector
n,m=map(int,input().split())
lists=[]
for i in range(n):
    a,b=map(int,input().split())
    lists.append((a,b))
lists=sorted(lists,key=lambda x:x[0])
ans=0
sums=0
for i in range(n):
    if sums+lists[i][1]<m:
        ans+=lists[i][0]*lists[i][1]
        sums+=lists[i][1]
    else:
        ans+=lists[i][0]*(m-sums)
        break
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
drink = dict()
cost = list()
ans = 0
for i in range(n):
    ab = [int(i) for i in input().split()]
    if ab[0] in drink:
        drink[ab[0]] += ab[1]
    else:
        cost.append(ab[0])
        drink[ab[0]] = ab[1]
#ここまで入力
cost.sort()
for i in cost:
    if m <= drink[i]:
        ans += m*i
        break
    else:
        m -= drink[i]
        ans += i * drink[i] 
    
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 = sorted(li)
cnt = 0
coin = 0
i = 0
while True:
    if cnt == m:
        break
    if li[i][1]>0:
        li[i][1]-=1
        coin += li[i][0]
        cnt+=1
    else:
        i += 1
print(coin)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
ab_lst = [list(map(int,input().split())) for i in range(n)]
ab_lst.sort()
total_money = 0
total_number = 0

for i in range(n):
    money = ab_lst[i][0]
    number = ab_lst[i][1]
    number = min(number, m-total_number)

    total_money += number * money
    total_number += number

    if total_number==m:
        break

print(total_money)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

N,M =[int(i) for i in input().split()]

AB = np.ones([N,2])


for i in range(N):
    AB[i,0],AB[i,1] = [int(i) for i in input().split()]
    
count=0
price=0

AB_new = AB[np.argsort(AB[:,0])]

for i in range(N):

    if count<=M: 
        count+=AB_new[i,1]
        if count<=M:
            price+=AB_new[i,0]*AB_new[i,1]
        elif count>M:
            price+=AB_new[i,0]*(M-count+AB_new[i,1])
    else:
        break

        
print(int(price))

Submission status: Accepted

Solution code:
#121_B
N,M=map(int,input().split())
Drink=[]
for _ in range(N):
    a,b=map(int,input().split())
    Drink.append((a,b))
Drink.sort(key=lambda x:x[0])

Sum=0
cnt=0
for i in range(N):
    a,b=Drink[i]
    tmp=min(M-cnt,b)
    Sum+=tmp*a
    cnt+=tmp
    if cnt==M:
        break

print(Sum)

Submission status: Accepted

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

store = list()
for i in range(n):
    a, b = map(int, input().split())
    store.append((a, b))

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

cost = 0
cur_num_drink = 0
for i in store:
    buy_num = min(i[1], m-cur_num_drink)
    cur_num_drink += buy_num
    cost += i[0] * buy_num
    if cur_num_drink == m:
        break

print(cost)

Submission status: Accepted

Solution code:
N ,M = (map(int , input().split()))
shop = []
for i in range(N):
    A ,B = (map(int , input().split()))
    shop.append((A ,B))
sorted_shop = sorted(shop,key = lambda x:x[0])
drink = 0
cost = 0
for a in sorted_shop:
    drink += a[1]
    cost += a[0] * a[1]
    if drink >= M:
        break
sabun = drink - M
ans = cost - (sabun * a[0])
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
ls = sorted([tuple(map(int,input().split())) for _ in range(N)])
cnt = 0
ans = 0
for a,b in ls:
    if cnt + b >= M:
        ans += a*(M-cnt)
        break
    cnt += b
    ans += a*b
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, readline().split())
AB = [tuple(map(int, readline().split())) for _ in range(N)]

AB.sort()

ans = 0
for yen, cnt in AB:
    if M == 0:
        break
    ans += yen * min(cnt, M)
    M -= min(cnt, M)
print(ans)

Submission status: Accepted

Solution code:
import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, readline().split())
AB = [tuple(map(int, readline().split())) for _ in range(N)]

AB.sort()

ans = 0
while M != 0:
    for yen, cnt in AB:
        ans += yen * min(cnt, M)
        M -= min(cnt, M)
print(ans)

Submission status: Accepted

Solution code:
n , m = map(int,input().split())
dic = {}
for _ in range(n):
    lis = list(map(int,input().split()))
    a = lis[0]
    b = lis[1]
    if a not in dic:
        dic[a] = b
    else:
        dic[a] += b
s = sorted(dic.items())

answer = 0
for ss in s:
    if ss[1]>=m:
        answer += m*ss[0]
        print(answer)
        exit()
    else:
        answer += ss[1]*ss[0]
        m -= ss[1]
        continue

Submission status: Accepted

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

v = 0
ans = 0

for a, b in l:
    if b+v >= M:
        ans += a*(M-v)
        break
    else:
        ans += a*b
        v+=b

print(ans)

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()
ans = 0
for i in a:
  if m >= i[1]:  
    m -= i[1]
    ans += i[0]*i[1]
  else:
    ans += i[0]*m
    break
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n,m=mii()
arr=llint(n)

arr.sort()
ncnt=0
mcnt=0

for i in range(n):
    if ncnt ==m:
        continue
    elif ncnt + arr[i][1]<m:
        ncnt+=arr[i][1]
        mcnt+=arr[i][0]*arr[i][1]

    elif ncnt + arr[i][1]>=m:
        mcnt+=(m-ncnt)*arr[i][0]
        ncnt=m
print(mcnt)

Submission status: Accepted

Solution code:
N, M = [int(i) for i in input().split()]
ab = [[int(i) for i in input().split()] for _ in range(N)]
ab.sort(key=lambda x: x[0])
ans = 0
for a, b in ab:
    m = M
    M = max(M-b, 0)
    ans += a*(m-M)
print(ans)

Submission status: Accepted

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

li.sort()

ans = 0
for i in range(N):
    if li[i][1] < M:
        ans += li[i][0]*li[i][1]
        M -= li[i][1]
    else:
        ans += li[i][0]*M
        print(ans)
        exit()

Submission status: Accepted

Solution code:
from operator import itemgetter

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

ab.sort(key=itemgetter(0))

result = 0
for e in ab:
  count = min(m, e[1])
  result += e[0] * count
  m = max(m-count, 0)
print(result)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
lis = sorted([list(map(int,input().split())) for _ in range(n)])
su = 0
ans = 0
sa = 0
for i in lis:
    su += i[1]
    if su <= m:
        ans += i[0]*i[1]
        sa += i[1]
    else:
        ans += i[0] * (m-sa)
        break
print(ans)