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())
drinks = [None] * N
for i in range(N):
    drinks[i] = tuple(map(int, input().split()))
drinks.sort()
cans = M
cost = 0
for a_cost, num in drinks:
    if cans <= 0:
        break
    dr = min(cans, num)
    cost += dr * a_cost
    cans -= dr

print(cost)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
w=[list(map(int,input().split())) for i in range(n)]
w.sort(key=lambda x:x[0])  #1個目の要素で昇順並び替え

money=0 
num_drink=0 #mになるまで買う
for i in range(n):
    if num_drink==m:
        break
    elif num_drink + w[i][1] <= m:
        num_drink += w[i][1]
        money += w[i][0] * w[i][1]
    elif num_drink + w[i][1] > m:
        money += w[i][0] * (m - num_drink)
        num_drink += m - num_drink
print(money)

Submission status: Accepted

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

AB.sort()
count = 0
ans = 0
for i,j in AB:
  if count+j >= M:
    ans += (M-count)*i
    break
  else:
    count += j
    ans += j*i
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()

s = 0
ans = 0
for x, y in ab:
    if s+y>=M:
        ans += (M-s)*x
        break
    else:
        s += y
        ans += x*y
print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ans=[]
for i in range(n):
    a,b=map(int,input().split())
    ans.append([a,b])
ans=sorted(ans,key=lambda a:a[0])
money=0
cnt=m
for i in range(n):
    price=ans[i][0]
    num=ans[i][1]
    if m>0:
        if m <= num:
            money += m*price
            m=0
        else:
            m -= num
            money+=num*price
    elif m==0:
        break
print(money)

Submission status: Accepted

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

y,x = 0,0
for i in range(n):
    for j in range(l[i][1]):
        if m > x:
            y += l[i][0]
            x += 1
        else:
            break

print(y)

Submission status: Accepted

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

    ans = 0

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

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

    print(ans)

if __name__ == '__main__':
    main()

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

m = 0
ans = 0
while True:
  a, b = AB.pop()
  if m + b < M:
    ans += a*b
    m += b
  else:
    c = M - m
    ans += a*c
    break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N,M=map(int,input().split())
    X=[[0,0] for i in range(0,N)]
    for i in range(0,N):
        X[i][0],X[i][1]=map(int,input().split())

    X.sort()
    s=0
    cost=0
    for i in range(0,N):
        if s+X[i][1]>=M:
            cost+=(M-s)*X[i][0]
            break
        else:
            s+=X[i][1]
            cost+=X[i][0]*X[i][1]
    print(cost)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

_cnt=0
_sum=0
i=0
if N==1 or drink_list[i][1]>=M:
    _sum=drink_list[i][0]*M
else:
    while _cnt<=M:
        if _cnt+drink_list[i][1]>=M:
            break
        else:
            _sum+=drink_list[i][0]*drink_list[i][1]
            _cnt+=drink_list[i][1]
            i+=1
        #print(_sum,_cnt,i)
    _sum+=drink_list[i][0]*(M-_cnt)

print(_sum)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
lis = [None]*N
for i in range(N):
    lis[i] = list(map(int,input().split()))
lis2=sorted(lis)
money=0
number = 0
i=0
while True:
    if number+lis2[i][1]<M:
        number+=lis2[i][1]
        money+=lis2[i][0]*lis2[i][1]
        i+=1
    elif number+lis2[i][1] == M:
        money+=lis2[i][0]*lis2[i][1]
        break
    else:
        temp = M-number
        money+=lis2[i][0]*temp
        break
print(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=sorted(l)


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

Submission status: Accepted

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

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

print(tot)

Submission status: Accepted

Solution code:
N,m = map(int,input().split())
A = sorted([list(map(int,input().split())) for _ in range(N)])
cnt = 0
for i in range(N):
    cnt+=A[i][0]*min(m,A[i][1])
    m-=min(m,A[i][1])
print(cnt)

Submission status: Accepted

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

sum = 0
cnt = 0
for ab in AB:
    a,b = ab[0], ab[1]
    if cnt + b < M:
        sum += a * b
        cnt += b
    else:
        sum += a * (M-cnt)
        break
print(sum)

Submission status: Accepted

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


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

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

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

print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
l = [0 for _ in range(n)]
for i in range(n):
    l[i] = list(map(int, input().split()))
l_sort = sorted(l)
ans = 0
drink = 0
for j in range(n):
    cnt_lim = l_sort[j][1]
    cnt = 0
    while cnt < cnt_lim:
        ans += l_sort[j][0]
        cnt += 1
        drink += 1
        if drink == m:
            print(ans)
            exit()

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
ans = cnt = 0
ab = []
for i in range(n):
    a,b = map(int,input().split())
    ab.append([a,b])
ab.sort(key=lambda x:x[0])
i=0
while cnt<m:
    buy = min(ab[i][1],m-cnt)
    ans += ab[i][0]*buy
    cnt += buy
    i += 1
print(ans)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
l=[]
for i in range(N):
    A,B=map(int,input().split())
    l.append([A,B])
l.sort()
left_drinks=M
prices=0
for i in l:
    if left_drinks<=0:
        break
    drinks = min(i[1],left_drinks)
    left_drinks -= drinks
    prices += i[0] * drinks
print(prices)

Submission status: Accepted

Solution code:
n,m = [int(x) for x in input().split()]
ab = []
for _ in range(n):
    a,b = [int(x) for x in input().split()]
    ab.append([a,b])

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

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

print(price)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())#軒数、目標本数
ab = sorted(list(map(int, input().split())) for i in range(n))#値段と個数が格納された小リストが大リストの要素
ans = stock = 0
for i in range(n):#ab[x][y]　x番目のa,bのセットの中からy=1ならbの値y=0ならaの値
    for j in range(ab[i][1]):
        ans +=ab[i][0]
        stock += 1
        if stock == m:
            print(ans)
            exit()

Submission status: Accepted

Solution code:
S = input().split(" ")
N = int(S[0])
M = int(S[1])

arr = []
for i in range(N):
    Q = input().split(" ")
    arr.append([int(q)for q in Q])

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

count = 0
total = 0
for a in arr:
    if count + a[1] <= M:
        total += a[0] * a[1]
        count += a[1]
    else:
        total += a[0] * (M - count)
        count += (M - count)
        break

print(total)

Submission status: Accepted

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

ls.sort()
drink = 0
money = 0
for i in ls:
    for j in range(i[1]):
        money += i[0]
        drink += 1
        if drink >= m:
            print(money)
            sys.exit()

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
L=[tuple(map(int,input().split())) for i in range(N)]
#s = sorted(L, key = lambda x: x[1])
s = sorted(L)
cnt=0
ans=0
while cnt<M:
  for i in range(N):
    if (M-cnt)<s[i][1]:
      ans+=(M-cnt)*s[i][0]
      cnt+=(M-cnt)
      
    else:
      ans+=s[i][0]*s[i][1]
      cnt+=s[i][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()
s = 0
money = 0
for i in range(len(li)):
  s+=li[i][1]
  if s>= m:
    s -=li[i][1]
    nokori = m-s
    money += li[i][0]*nokori
    break
  else:
    money += li[i][0]*li[i][1]
print(money)

Submission status: Accepted

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

r = 0
kA = sorted(range(n), key=lambda k: A[k])
for i in range(n):
    r += A[kA[i]]*min(m, B[kA[i]])
    m -= B[kA[i]]
    if m <0:
        break
print(r)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

ch = m+0
ans = 0
ax = 0
while ch > 0:
    t_ab = ab[ax]
    if t_ab[1] <= ch:
        num = t_ab[1]
    else:
        num = ch
    ans += t_ab[0]*num
    ax += 1
    ch -= num

print(ans)

Submission status: Accepted

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

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

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

ans = 0
while m > 0:
    a, b = ab.pop(0)
    ans += min(m, b) * a
    m -= min(m, b)

print(ans)

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
import queue
import copy

# 最大公約数
def gcd(m,n):
  x = max(m,n)
  y = min(m,n)
  if x%y == 0:
    return y
  else:
    while x%y != 0:
      z = x%y
      x = y
      y = z
    else:
      return z

# 幅優先探索(BFS)でスタート座標(x, y)からの最大距離返す
def bfs(SS, x, y, H, W):#入力(座標系(迷路), x, y, xの端, yの端)
  x_next = [0, 0, -1, 1]
  y_next = [1, -1, 0, 0]
  tempx = x
  tempy = y
  mlength = 0
  q = deque()
  xytuple = (x, y, 0)
  q.append(xytuple)


  while q:
    xytuple = q.popleft()
    SS[xytuple[0]][xytuple[1]] = "x" #探索した場所は探索できないようにする
    for i in range(4): #このforで上下左右を調べてる
      tempx = xytuple[0] + x_next[i]
      tempy = xytuple[1] + y_next[i]
      #print(tempx, tempy, xytuple[2])
      #print(S)
      if(0 <= tempx and tempx < H and 0 <= tempy and tempy < W and SS[tempx][tempy] == "."):
        temptuple = (tempx, tempy, xytuple[2]+1)
        SS[temptuple[0]][temptuple[1]] = "x" #探索した場所は探索できないようにする
        mlength = max(mlength, xytuple[2] +1)
        q.append(temptuple)
      #print(q)
  return mlength


#X = str(input()).split()
#a = [int(x) for x in input().split()]

NM = str(input()).split()
N = int(NM[0])
M = int(NM[1])
A = []
ans = 0

for i in range(N):
  AB = str(input()).split()
  A.append([int(AB[0]),int(AB[1])])


A.sort()

#print(A[1])
count = 0

while True:
  if (M==0):
    break
  if not(A[count][1] == 0):
    ans += A[count][0]
    A[count][1] -= 1
    M -= 1
  else:
    count+=1



print(ans)

Submission status: Accepted

Solution code:
N_ken, M_hon = map(int, input().split())
ab = []
yen = 0
hon = 0

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

ab.sort()

for a, b in ab:
    tmp = min(M_hon - hon, b)
    yen += tmp * a
    hon += tmp
    
    if (hon == M_hon):
        break

print(yen)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ab=[]
for i in range(n):
    abi=list(map(int,input().split()))
    ab.append(abi)
ab.sort()
msum=0
asum=0
for i in range(n):
    ai,bi=ab[i]
    asum=asum+ai*bi
    msum=msum+bi  
    if msum>=m:
        break
asum=asum-ai*(msum-m)
print(asum)

Submission status: Accepted

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

p.sort(key=lambda x: x[0])
ans=0
for i in p:
    if i[1] >= m:
        ans += i[0] * m
    else:
        ans += i[0] * i[1]
    m -= i[1]

    if m <= 0:
        break
print(ans)

Submission status: Accepted

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

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

drink.sort()

x = 0
ans = 0
for a, b in drink:
   if (x + b <= m):
      ans += a * b
      x += b
   else:
      y = m - x
      ans += a * y
      break

print(ans)

Submission status: Accepted

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

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter

INPUT = lambda: sys.stdin.readline().rstrip()
MAP = lambda: map(int, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))

sys.setrecursionlimit(10 ** 9)


def main():
    N, M = MAP()
    AB = [LIST() for i in range(N)]
    L = sorted(AB, key=itemgetter(0))

    money = 0
    cnt = 0
    for i in range(N):
        for j in range(L[i][1]):
            money += L[i][0]
            cnt += 1
            if cnt == M:
                print(money)
                sys.exit()


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
f = lambda : map(int,input().split())
n,m = f()
ll = sorted([list(f()) for _ in range(n)])
ans = 0
for p, c in ll:
  ans += p*min(m,c)
  m -= c
  if m < 1:
    break
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
f = lambda : map(int,input().split())
n,m = f()
ll = sorted([list(f()) for _ in range(n)])

ans = 0
for p, c in ll:
  ans += p*min(m,c)
  m -= c
  if m < 1:
    break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for p, c in ll:
  ans += p*min(m,c)
  m -= c
  if m < 1:
    break

print(ans)

Submission status: Accepted

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

ans = 0
cnt = 0
for l in ll:
  if cnt + l[1] > m:
    ans += (m-cnt)*l[0]
    break
  else:
    cnt += l[1]
    ans += l[0]*l[1]

print(ans)

Submission status: Accepted

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

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

AB = sorted(AB)

answer = 0
for a, b in AB:
  if M > b:
    answer += a * b
    M -= b
  else:
    answer += a * M
    break

print(answer)

Submission status: Accepted

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

AB.sort()

ans=0

for ab in AB:
    if M==0:
        break
    if ab[1]<=M:
        M-=ab[1]
        ans+=ab[0]*ab[1]
    elif ab[1]>M:
        ans+=ab[0]*M
        M-=M

print(ans)

Submission status: Accepted

Solution code:
import numpy as np 

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

need = M
cost = 0

AB.sort()

for i in range(N):
    if need - AB[i][1] >= 0:
        need -= AB[i][1]
        cost += AB[i][0]*AB[i][1]
    else:
        cost += AB[i][0]*need 
        break    

print(cost)

Submission status: Accepted

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

Submission status: Accepted

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

s = 0
c = 0
for i in range(N):
    s += D[i][1]
    c += D[i][0] * D[i][1]
    if s >= M:
        c -= (s - M) * D[i][0]
        break

print(c)

Submission status: Accepted

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

ab.sort()
res=0
for i in range(len(ab)):
    if ab[i][1] < m: # buy all
        res+= (ab[i][0]*ab[i][1])
        m-= ab[i][1]
    else: # buy some
        res+= ab[i][0]*m
        break

print(res)

Submission status: Accepted

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

ab.sort()

ans = 0
for _ab in ab:
    if m == 0:
        break

    if _ab[1] <= m:
        ans += _ab[0]*_ab[1]
        m -= _ab[1]
    elif _ab[1] > m:
        ans += _ab[0]*m
        m = 0

print(ans)

Submission status: Accepted

Solution code:
from operator import itemgetter
n, m = map(int, input().split())
lis = []
for i in range(n):
    lis.append(list(map(int, input().split())))

lis = sorted(lis, key = itemgetter(0))
#print(lis)
money = 0
cnt = 0
for i in range(n):
    money += lis[i][0] * lis[i][1]
    cnt += lis[i][1]
    #print(money)
    if cnt >= m:
        money -= (cnt-m) * lis[i][0]
        break
print(money)

Submission status: Accepted

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

count, ans = 0, 0
for a, b in sorted(AB):
    x = min(b, M - count)
    count += x
    ans += a * x
    if count == M:
        break
print(ans)

Submission status: Accepted

Solution code:
def solve(n, m, AB):
    AB.sort()
    count, total = 0, 0
    for a, b in AB:
        if count + b >= m:
            total += a * (m - count)
            break
        else:
            count += b
            total += a * b
    return total

_n, _m = map(int, input().split())
_AB = [list(map(int, input().split())) for _ in range(_n)]
print(solve(_n, _m, _AB))

Submission status: Accepted

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

total_m, total_c = 0, 0
for money, count in a:
    if total_c + count >= M:
        total_m += (M-total_c)*money
        break
    total_m += count*money
    total_c += count
print(total_m)

Submission status: Accepted

Solution code:
def solve():
    N,M = map(int, input().split())
    # A = []; B = []
    AB = [list(map(int, input().split())) for _ in range(N)]
    AB.sort(key=lambda x:x[0])
    ret = 0
    # print(AB)
    while M>0:
        ab = AB.pop(0)
        if ab[1] < M:
            ret += ab[0]*ab[1]
        else:
            ret += ab[0]*M
            
        M -= ab[1]
        # print(ret,M)
    
    print(ret)
    
solve()

Submission status: Accepted

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

AB = []

for _ in range(N):
    AB.append([int(i) for i in input().split()])

AB = sorted(AB)

money = 0

for i in AB:
    a = M - i[1]
    if a > 0:
        M = a
        money += i[1]*i[0]
    else:
        money += M*i[0]
        break
print(money)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from math import factorial
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


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


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def MS(): return map(str, input().split())


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


# show_flg = False
show_flg = True

p = None
XY = None
N = None


def main():
    N, M = MI()
    AB = [None] * N

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

    AB = sorted(AB)

    ans = 0
    total = 0

    for i in range(N):
        price = AB[i][0]
        size = AB[i][1]

        if M < total + size:
            n = M - total
            ans += price * n
            total += n
        else:
            ans += price * size
            total += size

        if total >= M:
            break

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from operator import itemgetter

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

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

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

cnt = 0
ans = 0

for i in pair:
    if m - cnt >= i[1]:
        ans += i[0] * i[1]
        cnt += i[1]
    else:
        ans += i[0] * (m - cnt)
        break

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])
ans = 0
cnt = 0 
for a, b in AB:
    pre_cnt = cnt
    cnt += b
    if cnt >= m:
        ans += a*(m-pre_cnt)
        break
    else:
        ans += a*b
print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
ll = sorted(l)
count, total, i = 0, 0, 0
while count < m:
    count += ll[i][1]
    total += ll[i][0]*ll[i][1]
    i += 1
total += ll[i-1][0]*(m-count)
print(total)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
ll = sorted(l)
count = 0
total = 0
for i in range(n):
    if count < m:
        count += ll[i][1]
        total += ll[i][0]*ll[i][1]
    else:
        c = count-m
        total -= ll[i-1][0]*c
        print(total)
        exit()
    if i == n-1:
        c = count-m
        total -= ll[i][0]*c
        print(total)
        exit()

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
ll = sorted(l)
count = 0
total = 0
for i in range(n):
    if count < m:
        count += ll[i][1]
        total += ll[i][0]*ll[i][1]
    else:
        c = count-m
        total -= ll[i-1][0]*c
        print(total)
        exit()
    if i == n-1:
        d = m - count
        total += ll[i][0]*d
        print(total)
        exit()

Submission status: Accepted

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

d.sort()

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

print(ans)

Submission status: Accepted

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

n, k = map(int, input().split())
arr = list(tuple(map(int, input().split())) for _ in range(n))
arr = sorted(arr, key=lambda x:x[0])
res = 0
for i in range(n):
    tk = min(k, arr[i][1])
    res += tk*arr[i][0]
    k -= tk
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]

class Util():
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)

def main():
    N,M = cin.mapInt()
    A = cin.intListList(N)
    ans = 0
    A.sort()
    for i in range(N):
        b = min(M,A[i][1])
        ans += b * A[i][0]
        M-=b
    print(ans)
    return

if __name__ == "__main__":
    main()

Submission status: Accepted

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

AB.sort()

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

Submission status: Accepted

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

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

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

print(c)

Submission status: Accepted

Solution code:
from operator import itemgetter
n,m = map(int, input().split())
input_list = []
for _ in range(n):
    i,j = map(int, input().split())
    d = {'price': i, 'amount': j}
    input_list.append(d)

total = 0
target = m
sorted_list = sorted(input_list, key=itemgetter('price'))
for dic in sorted_list:
    price = dic['price']
    amount = dic['amount']
    if target <= amount:
        total += target*price
        break
    else:
        total += amount*price
        target -= amount
print(total)

Submission status: Accepted

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

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 A:A[0])
okane=0
remain=m
for i in range(n):
    if remain>0:
        if remain-AB[i][1]>0:
            okane+=AB[i][1]*AB[i][0]
            remain-=AB[i][1]
        else:
            okane+=remain*AB[i][0]
            remain=0
    else:
        break
print(okane)

Submission status: Accepted

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

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

ans = 0
for t in table:
  if m > t[1]:
    ans += t[1] * t[0]
    m -= t[1]
  else:
    ans += m * t[0]
    break
print(ans)

Submission status: Accepted

Solution code:
ab = []

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

drink = 0
money = 0

while True:
  for i in range(n):
    if ab[i][1] + drink >= m:
      money += ab[i][0] * (m - drink)
      print(money)
      exit()
    else:
      money += ab[i][0] * ab[i][1]
      drink += ab[i][1]