Problem:


Score : 300 points

Problem Statement

Hearing that energy drinks increase rating in those sites, Takahashi decides to buy up M cans of energy drinks.

There are N stores that sell energy drinks. In the i-th store, he can buy at most B_i cans of energy drinks for A_i yen (the currency of Japan) each.

What is the minimum amount of money with which he can buy M cans of energy drinks?

It is guaranteed that, in the given inputs, a sufficient amount of money can always buy M cans of energy drinks.

Constraints

All values in input are integers.

1 \leq N, M \leq 10^5

1 \leq A_i \leq 10^9

1 \leq B_i \leq 10^5

B_1 + ... + B_N \geq M

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
A_2 B_2
\vdots
A_N B_N

Output

Print the minimum amount of money with which Takahashi can buy M cans of energy drinks.

Sample Input 1

2 5
4 9
2 4

Sample Output 1

12

With 12 yen, we can buy one drink at the first store and four drinks at the second store, for the total of five drinks. However, we cannot buy 5 drinks with 11 yen or less.

Sample Input 2

4 30
6 18
2 5
3 10
7 9

Sample Output 2

130

Sample Input 3

1 100000
1000000000 100000

Sample Output 3

100000000000000

The output may not fit into a 32-bit integer type.



Sample input:
2 5
4 9
2 4


Sample output:
12

Submission status: Accepted

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

ab.sort()
rem = m
ans = 0

for a, b in ab:
    if rem <= b:
        ans += a * rem
        break
    else:
        ans += a * b
        rem -= b

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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


if __name__ == "__main__":
    print(solve())

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
amount = 0
money = 0
ab = [list(map(int, input().split())) for _ in range(n)]
sorted_ab = sorted(ab)
for i in range(n):
  if amount > m:
    break
  amount += sorted_ab[i][1]
  money += sorted_ab[i][0] * sorted_ab[i][1]
  if amount > m:
    money -= (sorted_ab[i][0] * (amount - m))
  
print(money)

Submission status: Accepted

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

for i in range(N):
    D.append(list(map(int, input().split())))

D.sort()
num = 0
cost = 0
i = 0
while num < M:
    cost += D[i][0] * min(D[i][1], M - num)
    num += min(D[i][1], M - num)
    i += 1

print(cost)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n):
    array = list(map(int, input().split()))
    l.append(array)

l.sort()

for i, j in l:
    if j >= m:
        sum += i * m
        m = 0
    else:
        sum += i * j
        m -= j
    if m == 0:
        break

print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
lis = [None]*N
ans = 0
for i in range(N):
  lis[i] = list(map(int,input().split()))
lis = sorted(lis,key = lambda x:x[0])
for j in range(N):
  if lis[j][1] >= M:
    ans += M*lis[j][0]
    break
  else:
    ans += lis[j][1]*lis[j][0]
    M -= lis[j][1]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n):
    if m > li[i][1]:
        an+=li[i][0]*li[i][1]
        m-=li[i][1]
    else:
        an+=m*li[i][0]
        print(an)
        exit()

Submission status: Accepted

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

li.sort()

li3 = []
for j in range(len(li)):
    li3.extend([li[j][0]]*li[j][1])
    if len(li3)>M:
        break
print(sum(li3[0:M]))

Submission status: Accepted

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

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

print(answer)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
a.sort()
ta = 0
tc = 0
for i in range(len(a)):
    tc += min(m, a[i][1])
    ta += min(m, a[i][1]) * a[i][0]
    m -= min(m, a[i][1])
    if m == 0:
        print(ta)
        exit()

Submission status: Accepted

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

drinks = []

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

ans = 0
for x,y in drinks:
	if y < m:
		ans += x*y
		m -= y
	else:
		ans += x*m
		break

print(ans)

Submission status: Accepted

Solution code:
def resolve():
    N,M = map(int,input().split())
    AB = []
    for i in range(N):
        a = list(map(int,input().split()))
        AB.append(a)
    AB.sort()
    yen,sum = 0,0
    for i in range(N):
        tmp = min(AB[i][1],M-sum)
        yen += tmp*AB[i][0]
        sum += tmp
        if (sum>=M):
            break
    print(yen)
resolve()

Submission status: Accepted

Solution code:
def resolve():
    N,M = map(int,input().split())#N軒､M本必要
    AB = []
    for i in range(N):
        a = list(map(int,input().split()))
        AB.append(a)
#    print()
#    print(AB)
    AB.sort()
#    print(AB)

    yen = 0
    sum = 0
    for i in range(N):
#        print(AB[i][0],AB[i][1])
        tmp = min(AB[i][1],M-sum) #購入本数
        yen += tmp*AB[i][0]
        sum += tmp
        if (sum>=M):
            break
    print(yen)
resolve()

Submission status: Accepted

Solution code:
n, m = map(int,input().split())
ab = []
for i in range(n):
    ai,bi = map(int,input().split())
    ab.append([ai,bi])
ab.sort(key=lambda x:x[0])

cost = 0
count = 0
i = 0
while True:
    if count + ab[i][1] <= m:
        cost += ab[i][0]*ab[i][1]
        count += ab[i][1]
    else:
        cost += (m-count)*ab[i][0]
        break
    if count == m:
        break
    i+=1
print(cost)

Submission status: Accepted

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

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

shop = sorted(ab)

#print(shop)
count = 0
rest = m
price = 0

for i in range(n):
    # print('# i: ' + str(i))
    # print('rest: ' + str(rest))
    if rest == 0:
        break

    num = shop[i][1]
#    print('num: ' + str(num))
    if num < rest:
        price += shop[i][0] * shop[i][1]
        rest = rest - shop[i][1]
#        print(price)
    else:
        price += shop[i][0] * rest
        break

print(price)

Submission status: Accepted

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

Submission status: Accepted

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

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


print(ans)

Submission status: Accepted

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

h=0
s=0
t=0
for i in range(n):
    h += L[i][1]
    if h >= m:
        t=h-m
        s=i
        break
r=0
for j in range(s+1):
    r += L[j][0]*L[j][1]
r -= t*L[s][0]
   
print(r)

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()
money = 0
i = 0
while m > 0:
    money += ab[i][0] * min(ab[i][1], m)
    m -= ab[i][1]
    i += 1
print(money)

Submission status: Accepted

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

ans=0
buy = 0
buy_sum = 0

for i in range(N):
	buy = min(AB[i][1], M-buy_sum)
	ans += AB[i][0]*buy
	buy_sum += buy
	if M==buy_sum:
		break
print(ans)

Submission status: Accepted

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

for i in range(n):
  cnt+=li[i][1]
  ans+=li[i][0]*li[i][1]
  if cnt==m:
    print(ans)
    exit()
  if cnt>m:
    ans-=(cnt-m)*li[i][0]
    print(ans)
    exit()

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
ABs = []
for i in range(N):
  A, B = map(int, input().split())
  ABs.append((A, B))
ABs.sort(key=lambda AB: AB[0])
#print(ABs)
r = 0
m = 0
for i in range(N):
  A, B = ABs[i]
  if m+B >= M:
    r += A*(M-m)
    break
  else:
    r += A*B
    m += B
print(r)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
lis = []
for i in range(n):
    info = list(map(int,input().split()))
    lis.append(info)
lis = sorted(lis)
mazai = 0
money = 0
for i in range(n):
    buy = min(lis[i][1], m-mazai)
    money += lis[i][0] * buy
    mazai += buy
    if mazai == m:
        break
print(money)

Submission status: Accepted

Solution code:


def main():

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

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

        ans += i[0]*i[1]
        M -= i[1]


    






    
if __name__== "__main__":
    main()

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc121/tasks/abc121_c
# C - Energy Drink Collector

n, m = list(map(int, input().split()))
ab_list = []

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

# 一番安いお店を探す
ab_list.sort(key=lambda val: val[0])
nokori = m
cost = 0

for a, b in ab_list:
    if nokori < b:
        cost += a * nokori
        break
    else:
        cost += a * b
        nokori -= b

print(cost)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
Z = [list(map(int, input().split()))for _ in range(N)]
Z = sorted(Z, key=lambda Z: Z[0])
Z.append([0,0])
q = 0
c = 0
for i in range(len(Z)):
    if q < M:
        q += Z[i][1]
        c += Z[i][0]*Z[i][1]
    else:
        c -= (q- M)* Z[i-1][0]
        print(c)
        exit()

Submission status: Accepted

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

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

nokori = M
res = 0
for s in stores:
    cnt = nokori if nokori - s[1] < 0 else s[1]
    res += cnt * s[0]
    nokori -= cnt
    if nokori <= 0: break
print(res)

Submission status: Accepted

Solution code:

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

rest, res = m, 0

for i in range(n):
    buy = min(rest, drinks[i][1])
    res += buy * drinks[i][0]
    rest -= buy

print(res)

Submission status: Accepted

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


def get_num():
    return int(input())


def get_nums(n):
    res = [0 for _ in range(n)]
    for i in range(n):
        res[i] = int(input())
    return res


def get_numbers():
    return map(int, input().split())

n, m = get_numbers()

stores = list()
for _ in range(n):
    a, b = get_numbers()
    stores.append((a, b))

cost = 0
for a, b in sorted(stores, key=lambda x: x[0]):
    num = min(b, m)
    cost += num * a
    m -= num
    if m == 0:
        break

print(cost)

Submission status: Accepted

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

store = sorted(store)

money = 0
items = 0

for i in range(len(store)):
    if items + store[i][1] >= m:
        money += store[i][0] * (m - items)
        break
    money += store[i][0] * store[i][1]
    items += store[i][1]

print(money)

Submission status: Accepted

Solution code:
import sys
n, m = list(map(int, input().split()))
aaa = []
bbb = []
for i in range(n):
  a, b = list(map(int, input().split()))
  aaa.append(a)
  bbb.append(b)
c = zip(aaa, bbb)
c = sorted(c)
aaa, bbb = [list(x) for x in zip(*c)]
num = 0
ans = 0
for i in range(n):
  if num + bbb[i] >= m:
    ans += (m - num) * aaa[i]
    print(ans)
    sys.exit()
  else:
    ans += aaa[i] * bbb[i]
    num += bbb[i]

Submission status: Accepted

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

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

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

    ans = 0
    rest = M
    for i in range(N):
        a, b = ab[i]
        if b <= rest:
            ans += a * b
            rest -= b
        else:
            ans += a * rest
            break
    print(ans)


if __name__ == "__main__":
    main()

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

count = 0
money = 0
i = 0

while count < M:
    money += AB[i][0] * AB[i][1]
    count += AB[i][1]
    i += 1

if count > M:
    tmp = count - M
    money -= AB[i-1][0]*tmp

ans = money
print(ans)

Submission status: Accepted

Solution code:
i=0
n,m=map(int,input().split())
arr=[]
while (i<n):
	a,b=map(int,input().split())
	arr.append([a,b])
	i+=1

arr.sort(key=lambda x:x[0])
s=0
money=0
i=0
left=m
while(left>0):
	if(arr[i][1]<left):
		left-=arr[i][1]
		money+=arr[i][1]*arr[i][0]
	else:
		money+=left*arr[i][0]
		left-=arr[i][1]
	i+=1

print(money)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
li = [[int(i) for i in input().split()] for _ in range(N)]
mn = 0
dr = 0

li.sort()
for l in li:
    if M - dr > l[1]:
        dr += l[1]
        mn += l[0] * l[1]
    else:
        mn += l[0] * (M - dr)
        break

print(mn)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
ab_list = [list(map(int, input().split())) for _ in range(N)]
ab_list.sort(key=lambda i: i[0])
count = 0
money = 0
for a, b in ab_list:
    buy = min(b, M - count)
    count += buy
    money += buy * a
    if count == M:
        break
print(money)

Submission status: Accepted

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

ab = []
for i in range(n):
    ab.append([int(_) for _ in input().split()])

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

money = 0
n_dri = 0
for i in range(len(ab)):
    mon_num = ab[i]
    if n_dri + mon_num[1] < m:
        money += mon_num[0] * mon_num[1]
        n_dri += mon_num[1]
    else:
        money += mon_num[0] * (m - n_dri)
        print(money)
        exit()

Submission status: Accepted

Solution code:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


def main():
	n,m = map(int,input().split())
	ab = defaultdict(int)
	for i in range(n):
		tmp =  list(map(int,input().split()))
		ab[tmp[0]]  += tmp[1]
	ab = list(reversed(sorted(ab.items(), key=lambda x:x[0])))
	ans = 0
	while m > 0:
		t = ab.pop()
		ans += t[0] * min(t[1],m)
		m-=t[1]
	print(ans)


def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
li=[list(map(int,input().split()))for _ in range(N)]
li.sort()
n=0
price=0
for i ,j in li:
  n+=j
  price+=i*j
  if n>M:
    price-=i*(n-M)
    break
print(price)

Submission status: Accepted

Solution code:
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd
from itertools import accumulate

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    N,M = map(int, sys.stdin.readline().split())
    l= [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
    s = sorted(l,key=lambda x:x[0])
    n=0
    for i in range(N):
        if M - s[i][1] > 0:
            M=M - s[i][1]
            n += s[i][0]*s[i][1]
        else:
            n += s[i][0]*M
            break
    print(n)

Submission status: Accepted

Solution code:
def main45():
    data = input().split()
    nm = []
    for i in range(2):
        nm.append(int(data[i]))
    ab = []
    for i in range(nm[0]):
        karid = input().split()
        karin = []
        for j in range(2):
            karin.append(int(karid[j]))
        ab.append(karin)
    ab.sort()
    result = 0
    kazu = 0
    while(nm[1]>0):
        if nm[1] <= ab[kazu][1]:
            result = result + nm[1] * ab[kazu][0]
            nm[1] = 0
        else:
            result = result + ab[kazu][1] * ab[kazu][0]
            nm[1] = nm[1] - ab[kazu][1]
            kazu = kazu + 1
    print(result)

if __name__ == "__main__":
    main45()

Submission status: Accepted

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

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

i = 0
while M != 0:
  if AB_sort[i][1] <= M:
    cost += AB_sort[i][0] * AB_sort[i][1]
    M -= AB_sort[i][1]
  else:
    cost += AB_sort[i][0] * M
    M = 0
  i += 1

print(cost)

Submission status: Accepted

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

Submission status: Accepted

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

import numpy as np

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

cnt=0
amt=0

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

print(amt)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
#ABC121C
import sys
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
n=hoge[0]
m=hoge[1]

a=[]
for i in range(0,n):
	tmp = input().split()
	hoge = list(map(lambda a: int(a), tmp))
	a.append((hoge[0],hoge[1]))
a.sort()

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


#print("---")
#print(m)
print(total)
#print(a)

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(reverse=True)

ans = 0
while m > 0:
    a, b = drink.pop()
    if m > b:
        ans += a * b
        m -= b
    else:
        ans += a * m
        m = 0

print(ans)

Submission status: Accepted

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

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

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

nd = 0
ncost = 0
for A,B in ab_arr:
    if nd+B >= M:
        ncost += (M-nd)*A
        break
    nd += B
    ncost += B*A

print(ncost)

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

cost = 0

for i in ab:
        if m > i[1]:
            m -= i[1]
            cost += i[0] * i[1]
            if m == 0:
                break
        else:
            cost += i[0] * m
            m = 0
            break

print(cost)

Submission status: Accepted

Solution code:
import sys
a = input().split()
a = [int(i) for i in a]
drink = []


for i in range(a[0]):
    b = input().split()
    b = [int(i) for i in b]
    drink.append(b)

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

while (a[1] > 0):
    if drink[0][1] > a[1]:
        count += drink[0][0] * a[1]
        a[1] = 0
    else:
        count += drink[0][0] * drink[0][1]
        a[1] -= drink[0][1]
    drink.pop(0)

print(count)

Submission status: Accepted

Solution code:
# 2019/07/25

from heapq import heappop,heappush,heapify

input=open(0).readline
n,m=map(int,input().split())

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

cnt=0
rem=m
while rem:
    a,b=heappop(que)
    c=min(b,rem)
    cnt+=a*c
    rem-=c

print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

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

x = 0
res = 0
i = 0
while True:
    a, b = ab[i]
    if x + b >= m:
        res += (m - x) * a
        break
    else:
        res += b * a
        x += b
    i += 1

print(res)

Submission status: Accepted

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

for i in range(N):

    a, b = (map(int, input().split()))
    store[i] = (a, b)

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

# print(store)

rest = M
index = 0
cost = 0
while (rest > 0):
    c, drink = store[index]
    if drink >= rest:
        drink = rest
        rest = 0
    else:
        rest -= drink
    cost += drink * c
    index += 1

print(cost)

Submission status: Accepted

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

ans = 0
m = 0
for a, b in sorted(dic.items()):
    if m + b >= M:
        ans += a * (M - m)
        break
    m += b
    ans += a * b

print(ans)

Submission status: Accepted

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

X = [list(map(int,input().split())) for _ in range(N)]

cheap = sorted(X, key=lambda X:X[0])

buy = M
cost = 0
for i in range(N):
	if cheap[i][1] <= buy:
		cost += cheap[i][0] * cheap[i][1]
		buy -= cheap[i][1]
	else:
		cost += cheap[i][0] * buy
		break

print(cost)

Submission status: Accepted

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

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

ans = ans + (m-s) * ab[li][0]
print(ans)

Submission status: Accepted

Solution code:
# ABC 121 C

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

arr = []

for i in range(N):
    arr.append(list(map(int, input().split())))

arr.sort()

sum = 0

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

print(sum)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

def temp(var):
    return var[0]

AB = sorted(AB, key=temp)
# https://www.programiz.com/python-programming/methods/built-in/sorted

num = 0
amount = 0

for i in range(N):
    if M > num + AB[i][1]:
        num += AB[i][1]
        amount += AB[i][0] * AB[i][1]
        #  print(num)
    else:
        amount += AB[i][0] * (M - num)
        break

print(amount)

Submission status: Accepted

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

m, p = 0, 0
for a, b in AB:
    if m+b>=M:
        p += (M-m)*a
        break
    m += b
    p += b*a

print(p)

Submission status: Accepted

Solution code:
import sys
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n)]
ab = sorted(ab,key=lambda x: x[0])
total,num=0,0
for i in range(n):
  for j in range(ab[i][1]):
    total+=ab[i][0]
    num+=1
    if num==m:
      print(total)
      sys.exit()

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])
yen = 0
bottle = 0
for a, b in ab:
  if bottle + b < m:
    yen += a * b
    bottle += b
  else:
    yen += a * (m - bottle)
    break
print(yen)

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()
ans = 0
count = 0

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

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
c = []
for i in range(a):
    d, e = map(int, input().split())
    c.append([d, e])
c.sort()
g = 0
for i in range(a):
    f = min(b, c[i][1])
    b -= f
    g += f * c[i][0]
    if b == 0:
        break
print(g)

Submission status: Accepted

Solution code:
n, m = list(map(int, input().split()))
a = []
b = []
data = []
for i in range(n):
    data.append(list(map(int, input().split())))
data.sort()
sum = 0
money = 0
index = 0
while sum + data[index][1]< m:
    sum += data[index][1]
    money += data[index][0] * data[index][1]
    del data[index]
money += (m - sum) * data[index][0]
print(money)

Submission status: Accepted

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