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:
#!/usr/bin/python3
# abc121_c

"""
Energy Drink Collector
"""
test = False


def main():
    """
    とにかく安い方からM本になるまで買い続ける。
    """
    N, M = map(int, input().split())
    l = []
    bottle = 0
    cost = 0

    for _ in range(N):
        # [値段, 在庫本数] の2xNリストをつくる。
        l.append(list(map(int, input().split())))

    # 安い順に並べる
    l.sort()
    # 安い店の在庫を全部買って、M本を超えたら中断

    for i in range(N):
        bottle += l[i][1]
        cost += l[i][0] * l[i][1]
        # 買いすぎた分を返品
        if bottle >= M:
            cost -= (bottle - M) * l[i][0]
            break

    # 合計金額を出力
    print(cost)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

num = 0
price = 0
for s in S:
	if s[1] + num < M:
		price += s[0] * s[1]
		num += s[1]
	else:
		price += s[0] * (M - num)
		break
    
print(price)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A = []
for i in range(N):
  key,value = map(int,input().split())
  dic = {"key":key,"value":value}
  A.append(dic)
sorted_A = sorted(A, key=lambda x:x['key'])
count = 1;
k = 0
for i in range(N):
  k += sorted_A[i].get("value")
  if k < M:
    count += 1
  else:
    break
result = 0
baught = 0
for i in range(count):
  baught += sorted_A[i].get("value")
  if baught < M:
    result += sorted_A[i].get("key") * sorted_A[i].get("value")
  else:
    result += sorted_A[i].get("key") * (sorted_A[i].get("value") - baught + M)
print(result)

Submission status: Accepted

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

data = [map(int,raw_input().split()) for i in xrange(N)]

data.sort()

cnt = 0
ans = 0
i = 0

while cnt < M:
    if data[i][1] + cnt < M:
        ans += data[i][1]*data[i][0]
        cnt += data[i][1]
    else:
        ans += data[i][0]*(M-cnt)
        break
    i += 1
print ans

Submission status: Accepted

Solution code:
# from collections import defaultdict
# N,M = list(map(int,input().split()))
# price_howmany = defaultdict(int)
import sys

stdin = sys.stdin

read_int = lambda : list(map(int,stdin.readline().split()))

N,M = read_int()
price_howmany = {}
price_list = []

for _ in range(N):
    tmp = read_int()
    price_list.append(tmp[0])
    if tmp[0] in price_howmany:
        price_howmany[tmp[0]] += tmp[1]
    else:
        price_howmany[tmp[0]] = tmp[1]
price_list = list(set(price_list))
price_list.sort()

def solve():
    price = 0
    global M
    for low_price in price_list:
        many = min(M,price_howmany.pop(low_price))
        price += many * low_price
        M -= many
        if M == 0: break
    print(price)

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
P = [list(map(int, input().split())) for i in range(N)]
P.sort()
ans = 0
for a, b in P:
    m = min(M, b)
    ans += a*m
    M -= m
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
a.sort(key = lambda x:x[0])
ans = 0
b = 0
flag = 0
for i in range(n):
    while a[i][1]:
        a[i][1]-=1
        b+=1
        ans += a[i][0]
        if b ==m:
            flag=1
            break
    if flag==1:
        break
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
n, m = map(int, input().split())
data = [list(map(int, input().split())) for i in range(n)]
std_data = sorted(data)
j = 0
min_total = 0
bought_num = 0
while True:
    bought_num += std_data[j][1]
    min_total += std_data[j][0] * std_data[j][1]
    if bought_num >= m:
        min_total -= std_data[j][0] * (bought_num - m)
        break
    else:
        j += 1
print(min_total)

Submission status: Accepted

Solution code:
N,M = [int(x) for x in input().split(' ')]
AB = {}
for i in range(N):
  a,b = [int(x) for x in input().split(' ')]
  if a in AB:
    AB[a] += b
  else:
    AB[a] = b
    
dc = sorted(AB.items())

c = 0
m = M
for s in dc:
  price, stock = s
  if stock >= m:
    c += price * m
    break
  else:
    c += stock * price
    m -= stock
    
print(c)

Submission status: Accepted

Solution code:
n, m= map(int, input().split())
c = []
for i in range(n):#h:高さ
    c.append([int(m) for m in input().split()])
c.sort()
ans = 0
buy = 0
for i in range(n):
    if buy + c[i][1] < m:
        buy += c[i][1]
        ans += c[i][0] * c[i][1]
    else:
        ans += (m - buy) * c[i][0]
        break
print(ans)

Submission status: Accepted

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

AB = sorted(AB)

result = 0
c = M
for a, b in AB:
    t = min(c, b)
    c -= t
    result += a * t

print(result)

Submission status: Accepted

Solution code:
# from collections import defaultdict
# N,M = list(map(int,input().split()))
# price_howmany = defaultdict(int)
import sys

stdin = sys.stdin

read_int = lambda : list(map(int,stdin.readline().split()))

N,M = read_int()
price_howmany = {}
# price_list = []

price_set = set()
for _ in range(N):
    tmp = read_int()
    # if tmp[0] not in price_set:
        # price_list.append(tmp[0])
    price_set.add(tmp[0])
    if tmp[0] in price_howmany:
        price_howmany[tmp[0]] += tmp[1]
    else:
        price_howmany[tmp[0]] = tmp[1]
# price_list.sort(reverse=True)
price_list = sorted(list(price_set))

# price_howmany = dict(price_howmany)

def solve():
    price = 0
    global M
    # while M > 0:
        # low_price = min(price_howmany.keys())
        # low_price = price_list.pop()
        # many = min(M,price_howmany.pop(low_price))
        # price += many * low_price
        # M -= many
    for low_price in price_list:
        many = min(M,price_howmany.pop(low_price))
        price += many * low_price
        M -= many
        if M == 0: break
    print(price)

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

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

remaining_demand = M
payment = 0
for price, stock in stores:
    if stock >= remaining_demand:
        payment += price * remaining_demand
        break
    else:
        payment += price * stock
        remaining_demand -= stock

print("{}".format(payment))

Submission status: Accepted

Solution code:
def get_input_row():
  return [int(i) for i in input().split(" ")]
     
inp = get_input_row()
N = inp[0]
M = inp[1]
item_dict = {}
num = 0
for i in range(N):
  a, b = get_input_row()
  if a in item_dict:
    item_dict[a] += b
  else:
    item_dict[a] = b

sorted_list = [k for k in item_dict.keys()]
sorted_list.sort()
money = 0
for price in sorted_list:
  if M > item_dict[price]:
    M -= item_dict[price]
    money += price * item_dict[price]
  else:
    money += price * M
    break
print(money)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
z=0;n,m,*l=map(int,open(0).read().split())
for s,t in sorted(zip(l[::2],l[1::2])):
  z+=s*min(m,t);m-=t
  if m<=0:print(z);break

Submission status: Accepted

Solution code:
import sys
n,m,*l=map(int,sys.stdin.read().split())
ans=0
for s,t in sorted(zip(l[::2],l[1::2])):
  ans+=s*min(m,t)
  m-=t
  if m<=0:
    print(ans)
    break

Submission status: Accepted

Solution code:
import sys
N,M = map(int,input().split())
List =[]
for i in range(N):
    tmp_a,tmp_b = map(int,input().split())
    List.append([tmp_a,tmp_b])
List.sort()
sum_a,sum_b = 0,0
for i in range(N):
    if M-sum_b > List[i][1]:
        sum_a += List[i][0]*List[i][1]
        sum_b += List[i][1]
    else:
        sum_a += List[i][0]*(M-sum_b)
        sum_b += M-sum_b
        print(sum_a)
        sys.exit()

Submission status: Accepted

Solution code:
import numpy as np
N,M = map(int,input().split())
A_s = []
for _ in range(N):
  A_s.append(list(map(int,input().split())))
## Aiの順にsortする
A_s = sorted(A_s,key=lambda x:x[0])
money = 0
num = 0
pre_num = 0
for a_s in A_s:
  num += a_s[1]
  if num <= M:
    money += a_s[1] * a_s[0]
    pre_num += a_s[1]
  else:
    money += (M-pre_num) * a_s[0]
    break
  #print(money)
print(money)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
lis = []
for _ in range(n):
  lis.append(list(map(int,input().split())))
lis.sort()
ans=0
for i in range(n):
  x,y = lis[i]
  if y >= m:
    ans += x*m
    print(ans)
    quit()
  ans += x * y
  m -= y
print(ans)

Submission status: Accepted

Solution code:
n,m,*l=map(int,open(0).read().split())
ans=0
for s,t in sorted(zip(l[::2],l[1::2])):
  ans+=s*min(m,t)
  m-=t
  if m<=0:
    print(ans)
    break

Submission status: Accepted

Solution code:
n,m,*l=map(int,open(0).read().split())
ans=0
for s,t in sorted(zip(l[::2],l[1::2])):
  ans+=s*min(m,t)
  m=max(m-t,0)
  if not m:
    break
print(ans)

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

Solution code:
from operator import itemgetter
k, b = map(int, input().split())
a=[]
from heapq import heappush, heappop
for i in range(k):
    ta,tb = map(int, input().split())
    a.append([ta,tb])
a = sorted(a, key=itemgetter(0), reverse=False)
s=0
t = 0
ans = 0
i = 0
while s<b:
    s+=1
    if t<a[i][1]:
        ans+=a[i][0]
        t+=1
    else:
        i+=1
        ans+=a[i][0]
        t=1    

print(ans)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n, m = map(int, input().split())
    l = sorted(tuple(int(s) for s in input().split()) for _ in range(n))
    ans = 0
    for a, b in l:
        if m == 0:
            break
        ans += min(m, b) * a
        m = max(m - b, 0)
    print(ans)

Submission status: Accepted

Solution code:
#写経をもとに

ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input().rstrip() 

n, m = na()
ab = []
for i in range(n):
    ab.append(na())
ab.sort(key=lambda x: x[0])
 
rem = m
ans = 0
for v in ab:
    buy = min(rem, v[1])
    ans += buy * v[0]
    rem -= buy
print(ans)

Submission status: Accepted

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

shop_list = [None] * N
for n in range(N):
    a, b = map(int, input().split())
    shop_list[n] = [a, b]

total = 0
for a, b in sorted(shop_list, key = lambda x: x[0]):
    if M > b:
        total += a * b
        M -= b
    else:
        total += a * M
        break
print(total)

Submission status: Accepted

Solution code:
#写経

import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces
 
n, m = na()
ab = []
for i in range(n):
    ab.append(na())
ab.sort(key=lambda x: x[0])
 
rem = m
ans = 0
for v in ab:
    buy = min(rem, v[1])
    ans += buy * v[0]
    rem -= buy
print(ans)

Submission status: Accepted

Solution code:
[n,m] = [int(i) for i in input().split()]
dic = {}
for i in range(n):
    [ai,bi] = [int(i) for i in input().split()]
    if ai in dic.keys():
        dic[ai] += bi
    else:
        dic[ai] = bi
sum = 0
ls = sorted(list(dic.keys()))
while m > 0:
    for i in range(len(ls)):
    #print(dic)
        if dic[ls[i]] >= m:
            sum += ls[i] * m
            m = 0
            break
        else:
            sum += dic[ls[i]]*ls[i]
            m -= dic[ls[i]]
print(sum)

Submission status: Accepted

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

shops = sorted(
    ab,
    key=lambda x: x[0]
)
paid = 0
for cost, stock in shops:
    num = min(m, stock)
    paid += num * cost
    m = m - num
    if m == 0:
        break
print(paid)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
N,M=(int(i) for i in input().split())
L=sorted([[int(i) for i in input().split()] for i in range(N)])
ans=0
num=0
while M>0:
  if M>L[num][1]:
    M-=L[num][1]
    ans+=L[num][0]*L[num][1]
    num+=1
  else:
    ans+=L[num][0]*M
    M=0
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split());
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[0])
ab.append([0, 1])
i = 0
ans = 0
while m - ab[i][1] >= 0:
  ans += ab[i][0] * ab[i][1]
  m -= ab[i][1]
  i += 1
print(ans + ab[i][0] * m)

Submission status: Accepted

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

data.sort(key = lambda x: x[0])
left = m
i = 0
ans = 0
while left != 0:
    if data[i][1] <= left:
        ans += data[i][0] * data[i][1]
        left -= data[i][1]
    else:
        ans += data[i][0] * left
        left = 0
    i += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
li = []
ans = 0
for i in range(N):
    AB = list(map(int,input().split()))	
    li.append(AB)
li.sort()
i=0
while M > 0:
    M -= li[i][1]
    ans += li[i][0]*li[i][1]
    if M < 0:
        ans -= abs(M)*li[i][0]
    i+=1
print(ans)

Submission status: Accepted

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

shop = []

ans = 0

num = 0

for i in range(N):
  shop.append(list(map(int, input().split())))
  
shop = sorted(shop)
  
for i in range(N):
  for b in range(shop[i][1]):
    if (num == M):
      break
    num += 1
    ans += shop[i][0]
    
print(ans)

Submission status: Accepted

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

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


a.sort()

for i in range(N):
	buy += a[i][1]
	pay += a[i][0]*a[i][1]
	if buy >= M:
		pay -= (buy-M)*a[i][0]
		break
print(pay)

Submission status: Accepted

Solution code:
s = input().split()
N = int(s[0])
M = int(s[1])
 
AB = {}
for i in range(N):
  data = input().split()
  if int(data[0]) in AB.keys():
    AB[int(data[0])] += int(data[1])
  else:
    AB[int(data[0])] = int(data[1])
AB = sorted(AB.items())
money = 0
num = 0
for A,B in AB:
  if num+B < M:
    money += A*B
    num += B
  elif num+B == M:
    money += A*B
    break
  elif num+B > M:
    money += A*(M-num)
    break
print(int(money))

Submission status: Accepted

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

AB = sorted(list(map(int,input().split())) for _ in range(N))
Money = 0
for A,B in AB:
    x = min(B,M)
    Money += A * x
    M -= x
print(Money)

Submission status: Accepted

Solution code:
s = input().split()
N = int(s[0])
M = int(s[1])
 
AB = {}
for i in range(N):
  data = input().split()
  if int(data[0]) in AB.keys():
    AB[int(data[0])] += int(data[1])
  else:
    AB[int(data[0])] = int(data[1])
AB = sorted(AB.items())
money = 0
num = 0
for A,B in AB:
  for b in range(B):
    num += 1
    money += A
    if num == M:
      break
      
  if num == M:
    break
  
print(int(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()
ans = 0
for _ in range(N):
    if AB[_][1] >= M:
        ans += AB[_][0]*M
        break
    else:
        ans += AB[_][0]*AB[_][1]
        M -= AB[_][1]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def c_energy_drink_collector(N, M, Drinks):
    drinks = sorted(Drinks)
    needs = M
    ans = 0
    for a, b in drinks:
        buy = min(needs, b)
        ans += a * buy
        needs -= buy
        if needs == 0:
            break
    return ans

N, M = [int(i) for i in input().split()]
Drinks = [[int(i) for i in input().split()] for j in range(N)]
print(c_energy_drink_collector(N, M, Drinks))

Submission status: Accepted

Solution code:
from sys import exit

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

shops = {}

for _ in range(N):
    A, B = map(int, input().split())
    if A in shops.keys():
        shops[A] += B
    else:
        shops[A] = B

shops = sorted(shops.items())
ans = 0

for k in shops:
    if M - k[1] <= 0:
        ans += k[0] * M
        break
    else:
        ans += k[0] * k[1]
        M -= k[1]

print(ans)

Submission status: Accepted

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

ans = 0
m = M
for x in xs:
    c = min(m, x[1])
    ans += x[0] * c
    m -= c
    if c == 0:
        break

print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
dic = {}
for i in range(N):
    A, B = map(int, input().split())
    if A in dic:
        dic[A] += B
    else:
        dic[A] = B
dic = sorted(dic.items())


sum = 0
for A, B in dic:
    if B < M:
        sum += A * B
        M -= B
    else:
        sum += A * M
        break

print(sum)

Submission status: Accepted

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

counter=0
amount=0
flag=0

for i in range(N[0]):
    if flag==1:
        break
    while(drinks[i][1]!=0):
        drinks[i][1] -=1
        counter +=1
        amount += drinks[i][0]
        if counter==N[1]:
            flag=1
            break
print(amount)

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

Submission status: Accepted

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

a, b = map(int, input().split())
d = []
for i in range(a):
    x, y = map(int, input().split())
    d.append((x, y))
d.sort()
count = 0
for i in range(a):
    if b <= d[i][1]:
        count += b * d[i][0]
        break
    else:
        b -= d[i][1]
        count += d[i][0] * d[i][1]
print(count)

Submission status: Accepted

Solution code:
b=list(map(int,input().split()))
LL=[]
for i in range(b[0]):
    LL.append(list(map(int,input().split())))
LL.sort()
x=0
z=0
y=b[1]
i=-1
#初めi=0で固定しリストの先頭削除をしていたが計算時間がそれなりにかかる
#i+=1でiを増やしていく方向で行かないといけない
while y>=0 and not LL==[]:
    i+=1
    if y<=LL[i][1]:
        print(x+LL[i][0]*y)
        break
    else:
        y-=LL[i][1]
        x+=LL[i][1]*LL[i][0]

Submission status: Accepted

Solution code:
n,m,*t=map(int,open(0).read().split());c=0
for a,b in sorted(zip(t[::2],t[1::2])):c+=a*min(m,b);m=max(0,m-b)
print(c)

Submission status: Accepted

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

temp_list = []
for _ in range(N):
    temp = list(map(int, input().split()))
    temp_list.append(temp)

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

yen_min = 0
for yen, honsu in sort_after:
    if M - honsu > 0:
        yen_min += yen * honsu
        M -= honsu
    else:
        yen_min += M * yen
        break

print(yen_min)

Submission status: Accepted

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

Submission status: Accepted

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

X = sorted(X, key = lambda x: x[0])
ans = 0
for i in range(N):
    if X[i][1] >= M:
        ans += M * X[i][0]
        break
    else:
        ans += X[i][1] * X[i][0]
        M -= X[i][1]

print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
dic = {}
count = 0
goukei = 0
 
for i in range(N):
  price,honsu = map(int, input().split())
  if price in dic:
    dic[price] += honsu
  else:
    dic[price] = honsu
dic = sorted(dic.items())
for kakaku, number in dic:
    nokori = M-count
    count += number
    if count >= M:
      goukei += nokori*kakaku
      break
    else:
      goukei += number*kakaku
print (goukei)

Submission status: Accepted

Solution code:
b=list(map(int,input().split()))
LL=[]
for i in range(b[0]):
    LL.append(list(map(int,input().split())))
LL.sort()
x=0
z=0
y=b[1]
i=-1
while y>=0 and not LL==[]:
    i+=1
    if y<=LL[i][1]:
        print(x+LL[i][0]*y)
        break
    else:
        y-=LL[i][1]
        x+=LL[i][1]*LL[i][0]

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
count=0
for i in range(N):
    count=M-AB[i][1]
    if count>=0:
        ans+=AB[i][0]*AB[i][1]
        M=count
    else:
        ans+=AB[i][0]*M
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

data.sort()
num = 0
# for x in data:
#     print(x)
    
for x in data:
    for xx in range(int(x[1])):
        M -= 1
        num += int(x[0])
        if(M == 0):
            break
    if(M == 0):
        break
print(num)

Submission status: Accepted

Solution code:
N,M = (int(i) for i in input().split())
dic = {}
drink = M
money = 0
for i in range(N):
  a,b = (int(i) for i in input().split())
  if a not in dic:
    dic[a] = b
  else:
    dic[a] += b
c = sorted(dic.keys())
for j in c:
  if drink > dic[j]:
    money += j * dic[j]
    drink -= dic[j]
  else:
    money += j * drink
    break
print(money)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,m = LI()
    aa = sorted([LI() for _ in range(n)])
    r = 0
    for a,b in aa:
        t = min(b,m)
        r += a * t
        m -= t

    return r


print(main())

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
lst=sorted([list(map(int,input().split())) for i in range(N)])
_sum_drink=0
money=0
for i in lst:
    if _sum_drink+i[1] < M:
        money += i[0]*i[1]
        _sum_drink += i[1]
    else:
        money += i[0]*(M-_sum_drink)
        _sum_drink += M-_sum_drink
    if _sum_drink == M:
        print(money)
        exit()

Submission status: Accepted

Solution code:
def main():
	N, M = map(int, input().split())
	S = []
	for i in range(N):
		a, b = map(int, input().split())
		S.append([a, b])
	sorted_shop_list = sorted(S, key=lambda x: x[0])
	cost = 0
	for i in sorted_shop_list:
		a = i[0]
		b = i[1]
		if b < M:
			M -= b
			cost += a * b
		else:
			cost += a * M
			break
	print(cost)
	return

if __name__ == '__main__':
	main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

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

m = 0
n = 0
cost = 0
while True:
  if m >= M:
    break
  m = m + B[n]
  cost = cost + A[n] * B[n]
  n = n + 1
if m != 0:
  cost = cost - A[n - 1] * (m - M)

print(cost)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
# A_2=0
# B_2=0
list_A=[]
list_B=[]
sum_num=0
for i in range(n):
    A,B = map(int,input().split())
    list_A.append(A)
    list_B.append(B)


list_AB = []
for i in range(n):
    list_AB.append( (list_A[i], list_B[i]))

list_AB.sort()
list_A , list_B = zip(*list_AB)
# list_A.sort()
# list_B.sort()
# print(list_A)
# print(list_B)


m_1=m
for i in range(n):
    m_2=m_1
    m_1=m_1-int(list_B[i])
    if m_1<0:
        sum_num=sum_num + int(list_A[i])*m_2
    else:
        sum_num=sum_num +int(list_A[i])*int(list_B[i])
    #print(sum_num)
    #print("m_1",m_1,"m_2",m_2)
    if m_1<0:
        break

print(sum_num)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Mar  9 21:40:34 2019

@author: iwata
"""

N,M = map(int, input().split())
numlist =[]
money = 0
count = 0
count1 = 0
count2 = 0

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

numlist.sort()

while count < M:
    while numlist[count1][1] > count2:
        money = money + numlist[count1][0]
        count = count + 1
        count2 = count2 + 1
        if count == M:
            break
    count1 = count1 + 1
    count2 = 0
    
print(money)

Submission status: Accepted

Solution code:
import numpy as np

N, M = map(int, input().split())
AB = []
for i in range(N):
    AB.append(list(map(int, input().split())))
    
AB = np.array(AB)
AB_sorted = AB[AB[:,0].argsort(),:]

cs = np.cumsum(AB_sorted[:,1])
n_full_store = (cs <= M).sum()
money_a = np.sum(AB_sorted[:n_full_store,0] * AB_sorted[:n_full_store,1])
if M - cs[n_full_store-1] > 0:
    money_b = (M - cs[n_full_store-1]) * AB_sorted[n_full_store,0]
elif M - cs[n_full_store-1] < 0:
               money_b = AB_sorted[0,0] * M
else:
    money_b = 0
print(money_a + money_b)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Mar  9 22:21:07 2019

@author: yuta
"""

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

def main(n,m,ab):
    ab.sort(key=lambda x:x[0])
    count = 0
    price = 0
    for i in range(n):
        for j in range(ab[i][1]):
            if count == m:
                break
            else:
                price += ab[i][0]
                count += 1
    print(price)
main(N,M,AB)

Submission status: Accepted

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

for z in range(0,N):
  d.append([int(z) for z in input().split(" ")])

r=M
ans=0
for z in sorted(d):
  if r==0:
    break
  if z[1]<=r:
     ans+=z[0]*z[1]
     r-=z[1]
  else:
    ans+=z[0]*r
    r=0

print("{:d}".format(ans))

Submission status: Accepted

Solution code:
init = input().split(' ')
init = [int(i) for i in init]
n,m= init[0],init[1]

ab = []

try:
	while True:
		inp1 = input().split(' ')
		inp1 = [int(i) for i in inp1]
		ab.append([inp1[0],inp1[1]])
except:
	pass

ab.sort()
total = sum([ab[j][0]*ab[j][1] for j in range(n)])
deltarget = sum([ab[j][1] for j in range(n)]) - m

while deltarget > 0:
	if deltarget - ab[len(ab)-1][1] > 0:
		total -= ab[len(ab)-1][0]*ab[len(ab)-1][1]
		deltarget -= ab[len(ab)-1][1]
		ab.pop(len(ab)-1)
	else:
		total -= ab[len(ab)-1][0]*deltarget
		break

print(total)