Problem:


Score : 300 points

Problem Statement

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

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

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

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

Constraints

All values in input are integers.

1 \leq N, M \leq 10^5

1 \leq A_i \leq 10^9

1 \leq B_i \leq 10^5

B_1 + ... + B_N \geq M

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
A_2 B_2
\vdots
A_N B_N

Output

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

Sample Input 1

2 5
4 9
2 4

Sample Output 1

12

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

Sample Input 2

4 30
6 18
2 5
3 10
7 9

Sample Output 2

130

Sample Input 3

1 100000
1000000000 100000

Sample Output 3

100000000000000

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



Sample input:
2 5
4 9
2 4


Sample output:
12

Submission status: Accepted

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

count = 0
total_price = 0
i = 0
while count < M:
  total_price += AB[i][0]*AB[i][1]
  count += AB[i][1]
  i += 1
  if i == N:
    break

if count == M:
  print(int(total_price))
else:
  print(int(total_price-(count-M)*AB[i-1][0]))

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
for i, j in ab:
    ans += min(m, j)*i
    m -= min(m, j)
    if m == 0:
        print(ans)
        exit()

Submission status: Accepted

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

SUM=0
for i in range(N):
  a,b=ab[i]
  x = min(M,b)
  SUM += a*x
  M -= x
  if M==0:break
    
print(SUM)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
D = sorted([list(map(int,input().split())) for n in range(N)])
ans = 0
num = 0

for a,b in D:
  num+=b
  ans+=a*b
  if M<=num:
    ans-=a*(num-M)
    break

print(ans)

Submission status: Accepted

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

num=0
money=0
i=0
while num<M:
    num+=AB[i][1]
    money+=AB[i][0]*AB[i][1]
    if i<N-1 and num<M:
    	i+=1

money+=AB[i][0]*(M-num)

print(money)

Submission status: Accepted

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

a.sort()
b1=0
b2=0
c=0

for i in range(n):
  b1, b2 = b1+a[i][1], b1
  if b1 <= m:
    c += a[i][0] * a[i][1]
  else:
    c += a[i][0] * (m - b2)
    break

print(c)

Submission status: Accepted

Solution code:
def main():
    n, m= map(int, input().split()) 
    inlis = list()
    for i in range(n):
        a, b = list(map(int, input().split()))
        inlis.append([a,b])
    inlis.sort(key = lambda x: x[0])
    #print(inlis)

    tmp = 0
    kane = 0

    for numlis in inlis:
        a = numlis[0]
        b = numlis[1]

        if tmp + b <= m:
            tmp += b 
            kane += a * b
        
        else:
            kau = m - tmp
            tmp += kau
            kane += a * kau

        if tmp == m:
            break
    print(kane)   


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

total_cost = 0
total_drink = 0
for i in range(N):
    total_cost += sorted_AB[i][0] * sorted_AB[i][1]
    total_drink += sorted_AB[i][1]

    if total_drink >= M:
        timing_count = i
        break

answer = total_cost - (total_drink - M) * sorted_AB[timing_count][0]

print(answer)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
Shop_List = [list(map(int,input().split())) for i in range(N)]
Shop_List = sorted(Shop_List, key=lambda x:x[0])
Number_Counter = 0
Yen_Counter = 0
for i in range(N):
    if Number_Counter + Shop_List[i][1] <= M:
        Number_Counter += Shop_List[i][1]
        Yen_Counter += Shop_List[i][0]*Shop_List[i][1]
    elif Number_Counter + Shop_List[i][1] > M:
        Yen_Counter += (M-Number_Counter)*Shop_List[i][0]
        Number_Counter = M
    elif Number_Counter == M:
        break

print(Yen_Counter)

Submission status: Accepted

Solution code:
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 > 0:
        ans += a*b
        m -= b
    elif m == b:
        ans += a*b
        m -= b
        break
    else:
        ans += a*m
        break
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
List = []
for _ in range(N):
    A, B = map(int, input().split())
    List.append((A, B))
List.sort(key=lambda x: x[0])
Res = 0
for i in range(N):
    A, B = List[i]
    if B <= M:
        M -= B
        Res += A*B
    else:
        Res += A*M
        break
print(Res)

Submission status: Accepted

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

Submission status: Accepted

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

sum_ = 0
cnt = 0
for ab in d:
    if cnt + ab[1] > M:
        sum_ += ab[0] * (M-cnt)
        break
    else:
        cnt += ab[1]
        sum_ += ab[0]*ab[1]
print(sum_)

Submission status: Accepted

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

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

money = 0

for i in range(n):
    if energy[i][1] < m:
        m -= energy[i][1]
        money += energy[i][1] * energy[i][0]
    else:
        money += energy[i][0] * m
        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()

ans = 0
for ab in AB:
    t = min(m, ab[1])
    ans += ab[0]*t
    m -= t

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

Submission status: Accepted

Solution code:
N, M = [int(n) for n in input().split()]
A = []
for i in range(N):
    a, b = [int(n) for n in input().split()]
    A.append((a,b))
SA = sorted(A)
ans = 0
while True:
    sa = SA.pop(0)
    if sa[1] < M:
        ans += sa[0]*sa[1]
        M -= sa[1]
    else:
        ans += sa[0] * M
        break
print(ans)

Submission status: Accepted

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

ans = 0

for a,b in drink:
    ans += a*min(b,m)
    m -= min(b,m)
    if m == 0:
        break

print(ans)

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 lst:
  ans+=min(m,i[1])*i[0]
  m-=i[1]
  if m<=0:
    break
print(ans)

Submission status: Accepted

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

cnt = 0
ans = 0
for v in xs:
    if cnt + v[1] < m:
        ans += v[0] * v[1]
        cnt += v[1]
    else:
        print(ans + v[0] * (m - cnt))
        exit()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def actual(N, M, AB):
    payment = 0

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

    for price, stock in shop_order_by_price_desc:
        if stock >= M:
            # 端数があるときは、残りの必要分だけ買えばよい
            return payment + (price * M)
        else:
            # 端数がないなら買い切る
            M -= stock
            payment += price * stock


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

print(actual(N, M, AB))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
s=[]
for i in range(n):
    a1,b1=map(int,input().split())
    s.append([a1,b1])
s.sort()
k=0
h=0
for i in range(n):
    h+=s[i][1]
    k+=s[i][0]*s[i][1]
    if h>=m:
        k-=(h-m)*s[i][0]
        break
print(k)

Submission status: Accepted

Solution code:
n, m=map(int, input().split())
l=[]
for i in range(n):
  l.append(list(map(int, input().split())))
l = sorted(l, reverse=False)  
#print(l)
drinks=0
ttl=0
add=0
for i in range(n):
  add=min(m-drinks, l[i][1])
  ttl=ttl+add*l[i][0]
  drinks+=add
  if drinks==m:
    print(ttl)
    exit()

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
cost = 0
for a, b in AB:
    if M >= cnt:
        cnt += b
        cost += a*b
        if cnt == M:
            print(cost)
            break
        elif cnt > M:
            cost += (M-cnt)*a
            print(cost)
            break

Submission status: Accepted

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

Submission status: Accepted

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

ans, buy = 0, 0
for i, j in sorted(a, key=lambda x:x[0]):
    tmp = min(m-buy, j)
    ans += tmp*i
    buy += tmp
    if buy == m: break

print(ans)

Submission status: Accepted

Solution code:
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n, m = MI()
    a_b = [LI() for _ in range(n)]
    a_b.sort(key=lambda x:x[0])
    cnt = 0
    ans = 0
    for i in range(n):
        a = a_b[i][0]
        b = a_b[i][1]
        if cnt + b < m:
            cnt += b
            ans += a*b
        else:
            ans += a*(m - cnt)
            break
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
(n,m,),*s=[[*map(int,i.split())]for i in open(0)]
s.sort()
ans = 0
for a,b in s:
    if m<1:
        break
    if m > b:
        ans += a*b
        m -= b
    else:
        ans += m*a
        m=0
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)

n, m = map(int, input().split())
readline = sys.stdin.readline
AB = [[int(i) for i in readline().split()] for _ in range(n)]

import math

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

ans = 0

while m > 0:
    for ab in AB:
        a, b = ab[0], ab[1]
        if m > b:
            ans += a*b
            m -= b
        else:
            ans += a*m
            m = 0
            
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

# https://atcoder.jp/contests/abc121


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

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

    n_drink = 0
    n_store = 0
    for i in range(N):
        n_drink += AB[i][1]
        n_store = i+1
        if n_drink >= M:
            n_last = M - (n_drink - AB[i][1])
            break

    ans = 0
    for i in range(n_store-1):
        ans += AB[i][0] * AB[i][1]

    ans += AB[n_store-1][0] * n_last

    return ans


print(main())

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[]
b=[]
for i in range(n):
    s=list(map(int,input().split()))
    a.append(s[0])
    b.append(s[1])
c=zip(a,b)
d=sorted(c)
#print(d)
#print(d[0][1])
yen=0
btl=0
for i in range(n):
    if d[i][1]+btl<m:
        yen+=d[i][0]*d[i][1]
        btl+=d[i][1]
    elif d[i][1]+btl>=m:
        yen+=d[i][0]*(m-btl)
        btl=m
    if btl==m:
        print(yen)
        exit()

Submission status: Accepted

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

while(m>0):
  num = min(ab[i][1],m)
  ans += ab[i][0]*num
  #print(ans,num)
  m -= num
 #print(m)
  i += 1
print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ablist=[]
for i in range(n):
  ab=list(map(int,input().split()))
  ablist.append(ab)
ablistsort=sorted(ablist)
ans=0
ko=0
for i in range(n):
  ans+=ablistsort[i][0]*ablistsort[i][1]
  ko+=ablistsort[i][1]
  if ko>m:
      ans-=(ablistsort[i][0]*ablistsort[i][1])
      ko-=ablistsort[i][1]
      while ko<m:
        ans+=ablistsort[i][0]
        ko+=1
print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ab=sorted([list(map(int,input().split())) for _ in range(n)])
ans=0
i=0
while i<n:
    if m>=ab[i][1]:
        ans+=(ab[i][0])*ab[i][1]
        m-=ab[i][1]
        i+=1
    else:
        ans+=(ab[i][0])*(m)
        break
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()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, m = map(int, input().split())
    drinks = list()
    ans = 0
    for _ in range(n):
        drinks.append(list(map(int, input().split())))
    drinks = sorted(drinks, key=lambda x: x[0])
    for drink in drinks:
        if drink[1] >= m:
            ans += drink[0] * m
            break
        else:
            ans += drink[0] * drink[1]
            m -= drink[1]
    print(ans)
            
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import math
import heapq


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


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

    D = []
    for i in range(N):
        a, b = map(int, input().split())
        heapq.heappush(D, (a, b))
    ans = 0
    while M > 0:
        a, b = heapq.heappop(D)
        if M > b:
            ans += a * b
            M -= b
        else:
            ans += M * a
            print(ans)
            exit()


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from heapq import heappush,heappop
n,m=map(int,input().split())
d=[]
for i in range(n):
  a,b=map(int,input().split())
  heappush(d,(a,b))
ans=0
while d:
  a,b=heappop(d)
  if m>b:
    ans+=a*b
    m-=b
  else:
    ans+=a*m
    break
print(ans)

Submission status: Accepted

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

while m > 0:
    if b[j] <= m:
        p += a[j] * b[j]
        m -= b[j]
        j += 1
    else:
        p += a[j] * m
        m = 0

print(p)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

count = 0
cost = 0
shop = 0
while count < M:
  buy = min(Z[shop][1], M - count)
  count += buy
  cost +=  buy * Z[shop][0]
  if count < M:
    shop += 1
  
print(cost)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def main():
    ans = 0
    n, m = map(int, input().split())
    all = []
    for i in range(n):
        all.append(list(map(int, input().split())))
    all.sort()
    for i in range(n):
        if m >= all[i][1]:
            m -= all[i][1]
            ans += all[i][0]*all[i][1]
        else:
            ans += all[i][0]*(m)
            break
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i, j in drink:
    if m != 0:
        if m >= j:
            ans += i * j
            m -= j
        else:
            ans += i * m
            break

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])
s = sorted(l, key=lambda x:x[0])
ans = 0
for i in range(n):
  a, b = s[i]
  if b <= m:
    ans += a*b
    m -= b
  else:
    ans += a*m
    break
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
items = [ tuple(map(int, input().split())) for _ in range(N) ]
items.sort()
ans = 0
m = 0
for item in items:
  a = min(M - m, item[1])
  m += a
  ans += a * item[0]
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0
inf = float("inf")

n,m = I()
a =[l() for _ in range(n)]

a.sort()
i = 0
while m != 0:
    if a[i][1] >= m :
        ans += m*a[i][0]
        break
    else:
        ans += a[i][0]*a[i][1]
        m -= a[i][1]
        i += 1

print(ans)

Submission status: Accepted

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

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
L = []
for i in range(N):
    a, b = map(int, input().split())
    L.append((a, b))
L = sorted(L, key=lambda x: x[0])

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,m = readInts()
AB = []
for i in range(n):
    a,b = readInts()
    AB.append((a,b))
AB = sorted(AB, key = lambda x:x[0])
#print(AB)
num = 0
cost = 0
for a,b in AB:
    if m >= num + b:
        num += b
        cost += a*b
    else:
        cost += a*(m - num)
        num = m
print(cost)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[0])
cnt = 0
cost = 0
i = 0
while i<N:
    a,b = A[i]
    if cnt+b<=M:
        cnt += b
        cost += a*b
    else:break
    i += 1
if cnt<M:
    a,b = A[i]
    cost += (M-cnt)*a
print(cost)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n,m=MI()
lis=[LI() for i in range(n)]
lis.sort()
pay=0
i=0
while m>0:
    pay+=lis[i][0]*min(m,lis[i][1])
    m-=min(m,lis[i][1])
    i+=1
print(pay)

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

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:
        D[A]+=B
    else:
        D[A]=B

L=[]
for m in D:
    L.append((m,D[m]))

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

S=0
I=0
while M>0:
    (A,B)=L[I]
    B=min(B,M)
    S+=A*B
    M-=B
    I+=1
print(S)

Submission status: Accepted

Solution code:
import numpy as np
N,M = (int(X) for X in input().split())
Shop = np.zeros((N,2),dtype=int)
for T in range(0,N):
    Shop[T,:] = (np.array([int(X) for X in input().split()]))
Shop = Shop[np.argsort(Shop[:,0])]
Rest = M
Pric = 0
for T in range(0,N):
    Pric += Shop[T,0]*Shop[T,1]
    Rest -= Shop[T,1]
    if Rest<0:
        Pric += Rest*Shop[T,0]
        break
print(Pric)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in ab:
  t = min(m,i[1])
  ans += i[0]*t
  m -= t
print(ans)

Submission status: Accepted

Solution code:
N,M = [int(i) for i in input().split()]
store = [[int(i) for i in input().split()] for j in range(N)]
store.sort()
tc = 0
for i in range(N):
    tc += min(store[i][1], M) * store[i][0]
    M -= store[i][1]
    if M <= 0:
        break
print(tc)

Submission status: Accepted

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

drinks.sort()

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

Submission status: Accepted

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

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

tp_list.sort()

cnt = 0
cost = 0
flg = False
for a, b in tp_list:
    for i in range(b):
        cnt += 1
        cost += a

        if cnt == M:
            flg = True
            break
    
    if flg:
        break

print(cost)

Submission status: Accepted

Solution code:
import numpy as np

N,M=map(int,input().split())
l=[]
for n in range(N):
    A,B=map(int,input().split())
    temp_l=[A,B]
    l.append(temp_l)
arr=np.array(l,dtype=np.int64)
# print(l)
# print(arr)

need=M
ans=0


col_num=0
# route=np.sort(arr,axis=0)  #numpyソートの仕方がおかしい
route=arr[np.argsort(arr[:,col_num])]
# print(route)
for i in range(N):
    if need >= route[i,1]:
        ans+=route[i,0]*route[i,1]
        need-=route[i,1]
        if need==0:
            break
        else:
            continue
    else:
        ans+=route[i,0]*need
        need=0
print(ans)

Submission status: Accepted

Solution code:
N, M = (int(x) for x in input().split())
L = []
for i in range(N):
  A, B = (int(x) for x in input().split())
  L.append((A,B))
L.sort()
tn = 0
tm = 0
for i in range(N):
  if L[i][1] < M-tn:
    tn += L[i][1]
    tm += L[i][0]*L[i][1]
  else:
    tm += L[i][0]*(M-tn)
    print(tm)
    quit()

Submission status: Accepted

Solution code:
import numpy as np

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

if __name__ == "__main__":
    N,M = list(map(int, input().split()))   
    AB = [list(map(int, input().split())) for _ in range(N)]
    AB.sort(key=lambda x: x[0])
#    print(AB)
    solve()

Submission status: Accepted

Solution code:
def resolve():
    N, M = list(map(int, input().split()))
    ls = []
    for _ in range(N):
        a, b = list(map(int, input().split()))
        ls.append([a, b])
    ls = sorted(ls, key=lambda x: x[0])
    ans = 0
    drink = 0
    for i in range(N):
        if drink >= M:
            break
        if drink + ls[i][1] >= M:
            ans += ls[i][0] * (M - drink)
            drink = M
        else:
            ans += ls[i][0] * ls[i][1]
            drink += ls[i][1]

    print(ans)
    return

resolve()

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
AB = [0] * N
B = [0] * N
for i in range(N):
    AB[i] = list(map(int, input().split()))
AB.sort()
price = 0
ans = 0
for i in range(N):
    if M <= AB[i][1]:
        ans += AB[i][0] * M
        break
    ans += AB[i][0] * AB[i][1]
    M -= AB[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)]

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

print(total)

Submission status: Accepted

Solution code:
n,m = [int(x) for x in input().split()];
pair = [];
(a,b) = (int(x) for x in input().split());
pair.append((a,b));
for i in range(1,n) :
    (a,b) = (int(x) for x in input().split());
    pair.append((a,b));

#newlst = sorted(pair,cmp=lambda x,y:cmp(x[0],y[0]));
pair = sorted(pair,key=lambda x:x[0]);

sum =0;
i = 0;
while m > 0 :
    if m >= pair[i][1] :
        m = m - pair[i][1];
        sum = sum + pair[i][0] * pair[i][1];
        i = i +1;
    else :
        sum = sum + m*pair[i][0];
        m = 0;

print(sum);

Submission status: Accepted

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

print(ans)