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:
num_shop, num_want = map(int, input().split())

shops = []

for i in range(num_shop):
  price, hold = list(map(int, input().split()))
  shops.append([price, hold])

shops = sorted(shops, key = lambda x:x[0])
  
num_bought = 0
total_price = 0

for shop in shops:
  if shop[1] + num_bought >= num_want:
    total_price += (num_want - num_bought) * shop[0]
    break
  else:
    total_price += shop[0] * shop[1]
    num_bought += shop[1]

print(total_price)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

N,M = map(int,input().split())
A = [list(map(int,input().split())) for i in range(N)]
A.sort()
drink = 0
yen = 0
for i in A:
    if drink + i[1] >= M:
        yen += (M - drink) * i[0]
        print(yen)
        exit()
    else:
        yen += i[1] * i[0]
        drink += i[1]
    #print(yen,drink)
print(A)

Submission status: Accepted

Solution code:

N, M = map(int, input().split())
A = []

for i in range(N):
    a, b = map(int, input().split())
    A.append([a, b])
A.sort(key=lambda x: x[0])
ans = 0
for i in range(N):
    money = A[i][0] * A[i][1]
    if M <= A[i][1]:
        ans += A[i][0]*M
        break
    ans += money
    M -= A[i][1]
    # print(ans)
print(ans)

Submission status: Accepted

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

money = 0
need = M
for shop in shops:
    if shop[1] >= need:
        print(money + need * shop[0])
        exit(0)
    need -= shop[1]
    money += shop[0] * shop[1]

Submission status: Accepted

Solution code:
import numpy as np
N,M = list(map(int,input().split()))
A = []
X = 0
ans = 0
for i in range(N):
    A.append(list(map(int, input().split())))
B = sorted(A)
for i in range(N):
  if (X + B[i][1])<M:
    ans += B[i][0]*B[i][1]
    X += B[i][1]
  else:
    ans += B[i][0]*(M-X)
    break
print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
s = []
for i in range(n):
  s.append(list(map(int,input().split())))
s.sort()
total,count = 0,0
for j in range(n):
  for k in range(s[j][1]):
    total += s[j][0]
    count += 1
    if count == m:
      break
  if count == m:
    break

print(total)

Submission status: Accepted

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

a.sort()
i = 0

while M > 0:
    if M - a[i][1] >= 0:
        ans += a[i][0] * a[i][1]
        M -= a[i][1]
    else:
        ans += a[i][0] * M
        M = 0
    i += 1


print(ans)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for n in range(N)]
AB=sorted(AB)
money=0
n=0
D=0
while D<M:
    money+=AB[n][0]*AB[n][1]
    D+=AB[n][1]
    n+=1
money-=AB[n-1][0]*AB[n-1][1]
D-=AB[n-1][1]
print(money+AB[n-1][0]*(M-D))

Submission status: Accepted

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

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

money = 0
amount = 0
for a, b in data:
  amount += b
  money += a *b
  excess = (amount - M)
  if excess >= 0:
    money -= a * excess
    break

print(money)

Submission status: Accepted

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

Store_List=[]
for i in range(n):
    ai,bi=map(int,input().split())
    Store_List.append([ai,bi])


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

have=0
money=0
mise_index=0
while True:
    # print(have,money)
    if have + Store_List[mise_index][1] < m:
       have+=Store_List[mise_index][1]
       money+=Store_List[mise_index][0]*Store_List[mise_index][1]
       mise_index+=1
    else:
        money+=Store_List[mise_index][0]*(m-have)
        break

print(money)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

drinks.sort()
count = 0
cost = 0
for idx, drink in enumerate(drinks):
    count += drink[1]
    cost += drink[0]*drink[1]
    if count >= M:
        break

cost -= drinks[idx][0] * (count - M)
print(cost)

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 = sorted(A)

yen = 0
num = 0

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
C = sorted([tuple(map(int, input().split())) for _ in range(N)], key=lambda x: x[0])
D = 0
E = 0
for i in range(N):
    if E + C[i][1] >= M:
        D += C[i][0]*(M - E)
        break
    D += C[i][0]*C[i][1]
    E += C[i][1]
print(D)

Submission status: Accepted

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

L = sorted(L)

res = 0
tmp = a[1]
for i in range(a[0]):
    if L[i][1] < tmp:
        res = res + L[i][0] * L[i][1]
        tmp = tmp - L[i][1]
    elif L[i][1] == tmp:
        res = res + L[i][0] * L[i][1]
        break
    else:
        res = res + L[i][0] * tmp
        break

print(res)

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

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

Submission status: Accepted

Solution code:
import numpy as np
n, m = list(map(int, input().split()))
ans = 0
pair = []
for i in range(n):
    pair.append(list(map(int, input().split())))

pair.sort()
i = 0
drinks = 0
while(True):
    if drinks + pair[i][1]  < m:
        drinks = drinks + pair[i][1]
        ans = ans + pair[i][0] * pair[i][1]
    else:
        ans = ans + pair[i][0] * (m - drinks)
        break
    i = i + 1
print(ans)

Submission status: Accepted

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

AB = sorted(AB)
#total = 0
money = 0
for i in range(N):
    m = min(AB[i][1], M)
    money += AB[i][0]*m
    M = M - m
    if M == 0:
        break

print(money)

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()
count = 0
kin = 0
ban = 0
while count < m :
    if a[ban][1] != 0 :
        count += 1
        kin += a[ban][0]
        a[ban][1] -= 1
    else :
        ban += 1
print(kin)

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 = np.array(AB)
AB = AB[AB[:,0].argsort(), :]

m = 0
s = 0
for n in range(N):
    s += AB[n][0]*AB[n][1]
    m += AB[n][1]
    if m>=M:
        s -= AB[n][0]*(m-M)
        break
print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding:utf-8


N, M = list(map(int, input().split()))

A = []
B = []
for i in range(N):
    info = list(map(int, input().split()))
    A.append(info[0])
    B.append(info[1])

AB = [[A[i], B[i]] for i in range(N)]

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

yen = 0
head = 0
temp_M = M
while(True):
    nokori = AB[head][1]
    for i in range(temp_M):
        yen += AB[head][0]
        temp_M -= 1
        nokori -= 1
        if nokori == 0:
            break
    head += 1
    if temp_M ==0:
        break
print(yen)

Submission status: Accepted

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

abss.sort()
sum = 0
for (a,b) in abss:
    if m > b:
        sum = sum + a*b
        m = m-b
    else:
        sum = sum + a*m
        break

print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n):
    a, b = map(int, input().split())
    lis.append([a, b])
lis.sort()
c = 0
ans = 0
while True:
    if m <= lis[c][1]:
        ans += m * lis[c][0]
        break
    else:
        ans += lis[c][0] * lis[c][1]
        m -= lis[c][1]
        c +=1
   
print(ans)

Submission status: Accepted

Solution code:
nums = list(map(int, input().split()))
N, M = nums[0], nums[1]
A = [0 for _ in range(N)]
B = [0 for _ in range(N)]

for i in range(N):
    nums = list(map(int, input().split()))
    A[i], B[i] = nums[0], nums[1]

import numpy as np
inds = np.argsort(A)
ans = 0
rem = M
i = 0
while rem > 0:
    num = min(B[inds[i]], rem)
    ans += A[inds[i]] * num
    rem -= num
    i += 1

print(ans)

Submission status: Accepted

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

p = 0
for a, b in S:
  if M <= b:
    # M個買う
    p += a * M
    break
  else:
    # b個買う
    p += a * b
    M -= b
print(p)

Submission status: Accepted

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

ab_sort = sorted(ab, key=lambda x: x[0])
ans = 0
num = 0
# a=money b=num
for a, b in ab_sort:
    if num + b >= M:
        ans += (M - num) * a
        break
    else:
        num += b
        ans += a * b
print(ans)

Submission status: Accepted

Solution code:
# 2019/03/09
# AtCoder Beginner Contest 121 - C

# Input
n, m = map(int,input().split())
ab = list()

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

ab.sort()

bottle = 0
sum = 0
for idx in range(n):
    if bottle + ab[idx][1] >= m:
        sum += ab[idx][0] * (m - bottle)
        break
    else:
        sum += ab[idx][0] * ab[idx][1]
        bottle += ab[idx][1]
    
# Output
print(sum)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
p=[]
for i in range(n):
  a,b=map(int,input().split())
  p.append((a,b))
  
p.sort(key=lambda x:x[0])
remain = m
res=0

for t in p:
  c=min(remain,t[1])
  res+=t[0]*c
  remain-=c
  if remain==0:
    break
print(res)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
cost = 0
for A, B in sorted((tuple(map(int, input().split())) for i in range(N)), key=lambda p: p[0]):
	bought = min(M, B)
	cost += A * bought
	M -= bought

print(cost)

Submission status: Accepted

Solution code:
from sys import stdin

n, m = map(int, raw_input().strip().split())
inp = stdin.readlines()

p = [[0, 0] for i in xrange(n)]
i = 0
for line in inp:
    p[i] = map(int, line.strip().split())
    i += 1

p.sort()

pay = 0
rem = m
for i in xrange(n):
    a, b = p[i]
    tob = min(b, rem)
    rem -= tob
    pay += (a * tob)

    if rem <= 0: break

print pay

Submission status: Accepted

Solution code:
N, M = [int(s) for s in input().split(' ')]
stores = []
for i in range(N):
    stores.append(tuple([int(s) for s in input().split(' ')]))
stores = sorted(stores, key=lambda s: s[0])
N_buy = 0
money = 0
for store in stores:
    if N_buy + store[1] < M:
        N_buy += store[1]
        money += store[1] * store[0]
    else:
        money += (M - N_buy) * store[0]
        break
print(money)

Submission status: Accepted

Solution code:
import numpy as np

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

A = []
B = []
for i in range(N):
    tmp = [int(i) for i in input().split()]
    A.append(tmp[0])
    B.append(tmp[1])

idx = np.argsort(A)
A = np.array(A)[idx]
B = np.array(B)[idx]

buy_cnt = 0
cost = 0
for m in range(N):
    buy = B[m]
    if buy_cnt + buy > M:
        buy = M - buy_cnt
    
    buy_cnt += buy
    cost += buy*A[m]

    if buy_cnt == M:
        break

print(cost)

Submission status: Accepted

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

AB = [None] * N
for i in range(N):
    AB[i] = list(map(int, input().split()))

AB.sort(key = lambda ab: ab[0])

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

for _ in [0]*n:
  a,b = map(int,input().split())
  if a in d.keys():
    d[a] = d[a] + b
  else:
    d[a] = b

l = list(d.keys())

l.sort()
s = 0

for t in l:
  if d[t] < m:
    m -= d[t]
    s += t*d[t]
  else:
    s += t*m
    break
print(s)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

N, M = map(int, input().split(" "))
A = {}
B = {}

for i in range(N):
    a, b = map(int, input().split(" "))
    A[i] = a
    B[i] = b

cost = 0
for k, v in sorted(A.items(), key=lambda x: x[1]):
    if M - B[k] > 0:
        M -= B[k]
        cost += v * B[k]
    else:
        cost += v * M
        break

print(cost)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul, xor
from copy import copy, deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits
from datetime import date

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N,M=MAP()
AB=[[0]*2 for i in range(N)]
for i in range(N):
    AB[i][0],AB[i][1]=MAP()

AB.sort()
sm=0
cnt=0
for i in range(N):
    a,b=AB[i]
    if cnt+b<=M:
        cnt+=b
        sm+=a*b
    else:
        sm+=a*(M-cnt)
        cnt=M
    if cnt==M:
        break
print(sm)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#121-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n,m=IL()
c=[IL() for i in range(n)]
c.sort()
cnt=0
ans=0
for i in range(n):
    if cnt+c[i][1]>=m:
        ans+=(m-cnt)*c[i][0]
        break
    else:
        cnt+=c[i][1]
        ans+=c[i][0]*c[i][1]
print(ans)

Submission status: Accepted

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

arr.sort()
ans = 0
for i, j in arr:
    for k in range(j):
        if m > 0:
            ans += i
            m -= 1
        else:
            break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

AB = sorted(AB)

drink = 0
money = 0
iter = 0
while drink < M:
    add = min(AB[iter][1], M-drink)
    drink += add
    money += add*AB[iter][0]
    iter += 1

print(money)

Submission status: Accepted

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

new_AB = sorted(AB, key=lambda x: x[0])
m = M
i = 0
cost = 0
while m > 0:
    item = new_AB[i][1]
    if item >= m:
        buy_count = m
    else:
        buy_count = item
    m -= buy_count
    cost += buy_count * new_AB[i][0]
    #print("cost ",cost)
    i += 1

print(cost)

Submission status: Accepted

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

data.sort()

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

Submission status: 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
s=0
for ab in AB:
    if M-cnt>ab[1]:
        cnt+=ab[1]
        s+=ab[0]*ab[1]
    else:
        s+=ab[0]*(M-cnt)
        break
print(s)

Submission status: Accepted

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

A = np.zeros(N)
B = np.zeros(N)
for i in range(N):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b 
index = np.argsort(A)
A = A[index]
B = B[index]

m = 0
n = 0
ans = 0
while m != M:
    hon = B[n]
    yen = A[n]
    if M - m - hon >= 0:
        m += hon
        ans += yen * hon
        n += 1
    else:
        ans += yen * (M - m)
        break
print(int(ans))

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())))
# print(A)
A.sort()
#print(A)
res,count=0,0
for i in range(N):
    res+=A[i][0]*A[i][1]
    count+=A[i][1]
    if(count==M):
        break 
    if(count>M):
        res-=A[i][0]*A[i][1]
        count-=A[i][1]
        for j in range(1,A[i][1]+1):
            res+=A[i][0]
            count+=1
            if(count==M):
                print(res)
                exit()

print(res)
exit()

Submission status: Accepted

Solution code:
from operator import itemgetter


N, M = list(map(int, input().split()))

a = []
for i in range(N):
    a.append(list(map(int, input().split())))

def main():
    b = sorted(a, key=itemgetter(0))
    # print(b)
    m = 0
    cost = 0
    for i in range(N):
        # print(b[i])
        if (m + b[i][1]) <= M:
            m += b[i][1]
            cost += (b[i][0] * b[i][1])
        else:
            cost += (b[i][0] * (M-m))
            return cost
    return cost

print(main())

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for i in range(N)]
AB = sorted(AB, key=lambda x: x[0])
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:
N,M=map(int,input().split())
C=[]
for i in range(N):
    C.append(list(map(int,input().split())))
D=sorted(C, key=lambda x: x[0])
#print(D)
i=0
sum1=0
while M>0:
    d=min(M,D[i][1])
    sum1+=D[i][0]*d
    M=M-d
    i=i+1
print(sum1)

Submission status: Accepted

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

line = []
for i in range(N):
    a,b = map(int,input().split())
    line.append((a,b,a*b))

line.sort()
ans = 0
for l in line:
    if M == 0:
        break
    a = l[0]
    b = l[1]
    if b<=M:
        ans += a*b
        M -= b
    else:
        ans += a*M
        break
print(ans)

Submission status: Accepted

Solution code:
N, M = (int(i) for i in input().split()) 

total = 0
sp = []
for i in range(N):
    a, b = (int(i) for i in input().split())
    sp.append((a,b)) 

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

#print(sp)
for sh in sp:    
    if M >= sh[1]:
        total += sh[0] * sh[1]
        M = M - sh[1]
    else:
        total += sh[0] * M
        M = 0
    if M == 0:
        break
print(total)

Submission status: Accepted

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

    A = []; B = []; i = 0
    while i < N:
        a, b = map(int, input().split(' '))
        A.append(a); B.append(b)
        i += 1
    
    A, B = zip(*sorted(zip(A, B)))
    
    count = M; money = 0
    for a, b in zip(A, B):
        while b:
            if count == 0:
                break
            count -= 1
            money += a
            b -= 1
    
    print(money)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

a = [0 for k in range(n)]
b = [0 for k in range(n)]

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

t = sorted(range(len(a)), key=lambda k: a[k])

cost = 0
nokori = m
for i in t:
    if(b[i]<=nokori):
        cost += a[i]*b[i]
        nokori = nokori - b[i]
    else:
        cost += a[i]*nokori
        nokori = 0
    if(nokori==0):
        break

print(cost)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

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

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

input = lambda: stdin.readline()
main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
kusuri=[]
for i in range(n):
    a,b=map(int,input().split())
    kusuri.append([a,b])
kusuri.sort()
c=0
N=0
ans=0
while c!=m:
    if c+kusuri[N][1] <=m:
        c+=kusuri[N][1]
        ans+=kusuri[N][1]*kusuri[N][0]
    else :
        ans+=(m-c)*kusuri[N][0]
        c=m
    N+=1
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])
t=0
ans=0
while(m>0):
  if(ab[t][1]<m):
    m-=ab[t][1]
    ans+=ab[t][0]*ab[t][1]
    t+=1
  else:
    ans+=ab[t][0]*m
    m=0
print(ans)

Submission status: Accepted

Solution code:
import collections
import itertools
import numpy as np
import sys
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,M = IL()
ab = [IL() for i in range(N)]

ab.sort()

cnt = 0
ans = 0
for a,b in ab:
    while b>0:
        ans += a
        M -= 1
        b -= 1
        if M == 0:
            break
    if M==0:
        break

print(ans)

Submission status: Accepted

Solution code:
import sys
sy=sys.stdin.readline
n,m=map(int,sy().split())
ab=[list(map(int,sy().split())) for i in range(n)]
ab.sort(key=lambda x:x[0])
ans,count=0,0
for i in ab:
    if count+i[1]<m:
        count+=i[1]
        ans+=i[0]*i[1]
    else:
        ans+=i[0]*(m-count)
        break
print(ans)

Submission status: Accepted

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

while m > 0:
    money += list[i][0]
    m -= 1
    list[i][1] -= 1
    if list[i][1] == 0:
        i += 1

print(money)

Submission status: Accepted

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

A_B.sort(key=lambda x: x[0])
count = 0
result = 0
for a, b in A_B:
    if count + b < M:
        count += b
        result += a * b
    else:
        result += a * (M - count)
        break

print(result)

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())))
# print(A)
A.sort()
#print(A)
res,count=0,0
for i in range(N):
    res+=A[i][0]*A[i][1]
    count+=A[i][1]
    if(count==M):
        break 
    if(count>M):
        res-=A[i][0]*A[i][1]
        count-=A[i][1]
        for j in range(1,A[i][1]+1):
            res+=A[i][0]
            count+=1
            if(count==M):
                print(res)
                exit()

print(res)
exit()

Submission status: Accepted

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

ans=0

mise=0

while 1:
  if(m==0):
    break
  
  if(hoge[mise][1]==0):
    mise+=1
  if(hoge[mise][1]>0):
    hoge[mise][1]-=1
    ans+=hoge[mise][0]
    m-=1
    
print(ans)

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    shops = []
    for _ in range(N):
        A, B = map(int, input().split())
        shops.append((A, B))
    #print(shops)

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

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

main()

Submission status: Accepted

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

Submission status: Accepted

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

L.sort()

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


print(tmp)

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()
count = 0
summ = 0
for i in range(n):
    if count + ab[i][1] >= m:
        buy = m - count
        summ += ab[i][0] * buy
        print(summ)
        exit()
    else:
        count += ab[i][1]
        summ += ab[i][0] * ab[i][1]

Submission status: Accepted

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

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

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

juice_num = 0
money = 0
for juice in juice_list:
    if juice_num + juice[1] < M:
        money += juice[0] * juice[1]
        juice_num += juice[1]
    else:
        money += (M - juice_num) * juice[0]
        juice_num += M - juice_num
        break

print(money)

Submission status: Accepted

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

for i in range(0, N):
    A, B = [int(i) for i in input().split()]
    shops.append((A, B))

shops.sort()

result = 0
rest_count = M
for shop in shops:
    if rest_count > shop[1]:
        result += shop[0] * shop[1]
        rest_count -= shop[1]
    else:
        result += shop[0] * rest_count
        break

print(result)

Submission status: Accepted

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

at_n_hon = m
money = 0
for AB in ABs:
    kau_hon = AB[1] if AB[1] <= at_n_hon else at_n_hon
    at_n_hon -= kau_hon
    money += kau_hon *AB[0]
    if at_n_hon == 0:
        break

print(money)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
d = {}
for _ in range(N):
    a,b = map(int,input().split())
    if a in d.keys():
        d[a] += b
    else:
        d[a] = b

count = M
ans = 0
for i in sorted(list(d.keys())):
    if d[i] < count:
        count -= d[i]
        ans += i*d[i]
    else:
        ans += i*count
        break

print(ans)