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: Wrong Answer

Solution code:
N, M = map(int,input().split())
A_list = []
B_list = []
for _ in range(N):
    AB = list(map(int,input().split()))
    A_list.append(AB[0])
    B_list.append(AB[1])
ans = 0
for _ in range(100):
    if B_list[A_list.index(min(A_list))] < M:
        ans += min(A_list) * B_list[A_list.index(min(A_list))]
        M -= B_list[A_list.index(min(A_list))]
        m = A_list.index(min(A_list))
        A_list.pop(m)
        B_list.pop(m)
    else:
        ans += min(A_list) * M
        print(ans)
        break

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
#N = 1
#M = 1
l1 = []
l2 = []
ans = 0
rest = M
for i in range(N):
	temp1, temp2 = map(int, input().split())
	#temp1 = 1
	#temp2 = 1
	l1.append(temp1)
	l2.append(temp2)

while True:
	min_index = l1.index(min(l1))
	ans += (min(l1) * l2[min_index])
	rest -= l2[min_index]
	if rest <= 0:
		break
	l1.pop(min_index)

print(ans)

Submission status: Wrong Answer

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

sum_money = 0
sum_drink = 0
for i in range(N):
    if sum_drink + AB[i][1] <= M:
        sum_drink += AB[i][1]
        sum_money += AB[i][0] * AB[i][1]
    else:
        sum_money += AB[i][0] * (M - sum_drink)

print(sum_money)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
dict = {}
for i in range(N):
	A, B = map(int, input().split())
	dict[A] = B
dict_sorted = sorted(dict.items())
sum = 0
ans = 0
for i in dict_sorted:
	k = float(i[0])
	v = float(i[1])
	ans = k * v + ans
	sum = sum + v
	if sum > M:
		break
a = sum - M
ans = ans - a*k
print(int(ans))

Submission status: Wrong Answer

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

import sys

def parse_input(lines_as_string = None):

    lines = []
    if lines_as_string is None:
        lines.append(input())
        tokens = lines[0].split(" ")
        n = int(tokens[0])
        m = int(tokens[1])
        for i in range(n):
            lines.append(input())
    else:
        lines = [e for e in lines_as_string.split("\n")][1:-1]
        print("lines=%s" % lines)
        tokens = lines[0].split(" ")
        n = int(tokens[0])
        m = int(tokens[1])

    a = []
    b = []
    for i in range(n):
        tokens = lines[i+1].split(" ")
        a.append(int(tokens[0]))
        b.append(int(tokens[1]))

    return (n, m, a, b)

def solve(n, m, a, b):

    
    s_a = sorted([(i, e) for i, e in enumerate(a)], key=lambda e: e[1])
    print("s_a=%s" % s_a)

    current = m
    total = 0
    tmp = 0
    for i, e in s_a:
        if current > b[i]:
            tmp = e * b[i]
            current = current - b[i]
        else:
            tmp = e * current
            current = 0

        total = total + tmp

#        print("i=%d, total=%d" % (i, total))
        if current == 0:
            break

    return total

def main():

    print("%d" % solve(*parse_input()))

if __name__ == '__main__':

    main()

Submission status: Wrong Answer

Solution code:
N, M = map(long, raw_input().split())
A = list()
for i in xrange(N):
    a, b = map(long, raw_input().split())
    A.append((a,b))

A.sort()

count = 0
cost = 0L

for (a, b) in A:
    if count + b >= M:
        cost += a * (M - count) 
        print str(cost)
    else:
        count += b
        cost += a * b

Submission status: Wrong Answer

Solution code:
from collections import OrderedDict
if __name__ == "__main__":
    NM = list(map(int, input().split()))
    n = NM[0]
    m = NM[1]
    mydict = {}
    for i in range(n):
        money_can = list(map(int, input().split()))
        money = money_can[0]
        can = money_can[1]
        mydict[money] = can
    buynow = 0
    moneynow = 0

    mydict = OrderedDict(sorted(mydict.items()))
    for i in mydict.keys():
        if(buynow >= m):
            break
        if(i in mydict.keys()):
            if(mydict[i] + buynow <= m):
                moneynow += mydict[i]*i
                buynow += mydict[i]
            else:
                need = m - buynow
                moneynow += need*i
                buynow += need
        else:
            continue
    print(moneynow)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
n, m = map(int, raw_input().split())

dic = {} # yen: many

for i in range(n):
    a, b = map(int, raw_input().split())
    dic.update({a:b})

dic = sorted(dic.items())

count = 0
yen = 0
for k, v in dic:

    if v < m-count:
        yen += k*v
        count += v
    else:
        yen += k*(m-count)
        print yen
        break

Submission status: Wrong Answer

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

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
def main():
    N, M = map(int, input().split())
    shop_drink = [[int(i) for i in input().split()] for n in range(N)]
    # ドリンクの金額でソートする
    # sorted(shop_drink)
    shop_drink.sort()
    buy_drinks = 0
    buy_amount = 0

    for sd in shop_drink:
        # 購入可能数と購入済数の和が，目標数を超えない場合
        if buy_drinks + sd[1] <= M:
            # 購入済数を増やす
            buy_drinks += sd[1]
            # 合計金額に加算する
            buy_amount += sd[0] * sd[1]
        # 購入可能数と購入済み数の和が，目標数を超える場合
        else:
            # 必要数を計算
            temp = M - buy_drinks
            buy_amount += sd[0] * temp
            print(buy_amount)
            return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin

N,M = map(int, input().split(' '))
shop = [stdin.readline().rstrip().split(' ') for i in range(N)]
shop = sorted(shop)

sum = 0
for i in range(N) :
  if M > int(shop[i][1]) :
    sum += int(shop[i][0]) * int(shop[i][1])
    M -= int(shop[i][1])
  else :
    sum += int(shop[i][0]) * M
    M = 0
    break
    
print(sum)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
drinks = dict()
for _ in range(n):
    (a, b) = map(int, input().split())
    drinks[a] = b
p = 0
keys = sorted(drinks.keys())
for k in keys:
    if drinks[k] < m:
        p += k * drinks[k]
        m -= drinks[k]
    else:
        p += k * m
        break
print(p)

Submission status: Wrong Answer

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())))
  
sorted(shop)
  
for i in range(N):
  for b in range(shop[i][1]):
    if (num == M):
      break
    num += shop[i][1]
    ans += shop[i][0]
    
print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(long, raw_input().split())
A = list()
for i in xrange(N):
    a, b = map(long, raw_input().split())
    A.append((a,b))

A.sort()

count = 0
cost = 0

for (a, b) in A:
    if count + b >= M:
        cost += a * (M - count) 
        print str(cost)
    else:
        count += b
        cost += a * b

Submission status: Wrong Answer

Solution code:
from collections import OrderedDict
if __name__ == "__main__":
    NM = list(map(int, input().split()))
    n = NM[0]
    m = NM[1]
    mydict = {}
    for i in range(n):
        money_can = list(map(int, input().split()))
        money = money_can[0]
        can = money_can[1]
        mydict[money] = can
    buynow = 0
    moneynow = 0

    mydict = OrderedDict(sorted(mydict.items()))
    for i in mydict.keys():
        if(buynow >= m):
            break
        if(i in mydict.keys()):
            if(mydict[i] + buynow < m):
                moneynow += mydict[i]*i
                buynow += mydict[i]
            else:
                need = m - buynow
                moneynow += need*i
                buynow += need
        else:
            continue
    print(moneynow)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l={}
k=[]
ans=0
num=0
v=0
for i in range(n):
    a,b=map(int,input().split())
    if a in l:
        l[a]=l[a]+b
    else:
        l[a]=b
    k.append(a)
set(k)
k.sort()
while True:
    if num+l[k[v]]<m:
        ans+=k[v]*l[k[v]]
        num+=l[k[v]]
        v+=1
    else:
        ans+=(m-num)*k[v]
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
AB=[[int(j) for j in input().split()] for i in range(N)]
ans=0
AB = sorted(AB)
num, ans, i,j =0,0,0,1
while num<M:
    if j<=AB[i][1]:
        ans += AB[i][0]
        num+=1
        j+=1
        print("num",num)
    else:
        i+=1
        j=1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l={}
k=[]
ans=0
num=0
v=0
for i in range(n):
    a,b=map(int,input().split())
    if a in l:
        l[a]=l[a]+b
    else:
        l[a]=b
    k.append(a)
set(k)
while True:
    if num+l[k[v]]<m:
        ans+=k[v]*l[k[v]]
        num+=l[k[v]]
        v+=1
    else:
        ans+=(m-num)*k[v]
        break
print(ans)

Submission status: Wrong Answer

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

AB = {}
for i in range(N):
  data = input().split()
  AB[int(data[0])] = int(data[1])

money = 0
num = 0
for A,B in sorted(AB.items()):
  if num+B < M:
    money += A*B
    num += B
  else:
    money += A*(M-num)
    break
  
print(money)

Submission status: Wrong Answer

Solution code:
from sys import stdin


def a(input_string):
    N, M = [int(x) for x in input_string[0].split()]
    C = input_string[1:]
    temp = [string.split() for string in C]
    D = []
    for i in range(len(temp)):
        D.append([int(word) for word in temp[i]])
    #print(D)
    get_count = 0
    min_cost = 10000000000000000
    cost = 0
    D = sorted(D, key=lambda x: x[0])
    for i in range(N):
        get_count += 1
        cost += D[i][0]
        if get_count >= M:
            if cost < min_cost:
                min_cost = cost
    return min_cost


def main():
    input_line = stdin.readlines()
    answer = a(input_line)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,M=(int(i) for i in input().split())
lst1=[]
lst2=[]
for i in range(N):
  a,b=(int(i) for i in input().split())
  lst1.append(a)
  lst2.append(b)
lst1copy=sorted(lst1)
L=[0]
S=[0]
A=lst1copy[0]

for i in range(N):
  n=lst1.index(lst1copy[i])
  L.append(L[i]+lst1[n]*lst2[n])
  S.append(S[i]+lst2[n])
  if S[i]>=M:
    break
if S[-1]==M:
  print(L[-1])
else:
  print(L[-2]+(M-S[-2])*lst1copy[n-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

@author: iwata
"""

N,M = map(int, input().split())
numlist =[]
num = 0

for i in range(N):
    A,B = map(int, input().split())
    for j in range(B):
        numlist.append(A)

numlist.sort()


sum(numlist[:M])
    
print(num)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
d = {}
for _ in range(N):
    a, b = map(int, input().split())
    d[a] = b
d = sorted(d.items(), key=lambda x: x[0])
ans = 0
for (a, b) in d:
    if b < M:
        ans += a * b
        M -= b
    else:
        ans += a * M
        break
    if M == 0:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

N,M = map(int,input().split())
A = []
for i in range(N):
    A.append([int(x) for x in input().split()])

AB = np.array(A)

AB = AB[np.argsort(AB[:,0])]

yen = 0
cnt = 0
i = 0
while(1):
    cnt_ = cnt + AB[i,1]
    if(cnt_ >= M):
        yen += (M - cnt)*AB[i,0]
        break
    yen += AB[i,0]*AB[i,1]
    print(cnt_,yen)
    cnt = cnt_
    i += 1


print(yen)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
a = [list(map(int,input().split())) for i in range(N)]
a.sort(key=lambda x:x[0])
print(a)
ans = 0
nokori = M
for j in range(N):
	ans += a[j][0]*min(a[j][1],nokori)
	nokori -= a[j][1]
	if nokori <= 0:
		print(ans)
		exit()

Submission status: Wrong Answer

Solution code:
N,M =map(int,input().split())
List=[[int(j) for j in input().split()] for i in range(N)]
num_dict = dict()
for i in range(N):
    key = List[i][0]
    val = List[i][1]
    num_dict[key]=val
new_dict =dict()
for k,v in sorted(num_dict.items()):
    new_dict[k]=v
new_dict
M_res = 0
M_res +=M

ANS = 0

while M_res > 0:
    for i in new_dict.keys():
        if M_res <= new_dict[i]:
            ANS +=  i * M_res
            M_res -=M_res
        else:
            ANS += new_dict[i] * i
            M_res -=new_dict[i]
            
        if M_res ==0:
            break
print(ANS)

Submission status: Wrong Answer

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

AB = {}
for i in range(N):
  data = input().split()
  AB[int(data[0])] = int(data[1])

money = 0
num = 0
for A,B in sorted(AB.items()):
  if num+B < M:
    money += A*B
  else:
    money += A*(M-num)
    break
  num += B
  
print(money)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
d = {}
for _ in range(N):
    a, b = map(int, input().split())
    d[a] = b
d = sorted(d.items(), key=lambda x: x[0])
ans = 0
for (a, b) in d:
    if b < M:
        ans += a * b
        M -= b
    else:
        ans += a * M
        break
print(ans)

Submission status: Wrong Answer

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

shop_dic = {}
for _ in range(N):
    a, b = map(int, input().split())
    shop_dic[a] = b

total = 0
for a in sorted(shop_dic.keys()):
    b = shop_dic[a]
    if M < b:
        total += a * M
        break
    else:
        total += a * b
        M -= b
print(total)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(N)]
KOSU=0
money=0
A=[AB[i][0] for i in range(N)]
A.sort()
flag1=False
flag2=False
for i in A:
  for j in AB:
    if j[0] is i:
      for t in range(j[1]):
        money +=j[0]
        KOSU+=1
        if KOSU==M:
          print(money)
          flag1=True
          flag2=True
          break
    if flag1:break
  if flag2:break

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

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

e = [[int(i) for i in input().split()] for i in range(n)] 

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

money = 0
mcount = m

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

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
A=[]
ab={}
s=0
for i in range(n):
    a,b=map(int,input().split())
    A.append(a)
    if a in ab:
        ab[a]+=b
    else:
        ab[a]=b
A=sorted(A)
k=0
while m>0:
    if m>=ab[A[k]]:
        m-=ab[A[k]]
        s+=ab[A[k]]*A[k]
    else:
        s+=A[k]*m
        m=0
    k+=1
print(s)

Submission status: Wrong Answer

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 = defaultdict(list)
array = []
for i in range(a):
    x, y = map(int, input().split())
    d[x].append(y)
    array.append(x)
array.sort()
count = 0
for i in array:
    if b <= d[i][0]:
        count += max(b, 0) * i
        break
    else:
        t = d[i][0]
        b -= t
        count += t * i
    d[i].pop()
print(count)

Submission status: Wrong Answer

Solution code:
N,M=(int(i) for i in input().split())
lst1=[]
lst2=[]
for i in range(N):
  a,b=(int(i) for i in input().split())
  lst1.append(a)
  lst2.append(b)
lst1copy=sorted(lst1)
L=[0]
S=[0]
A=M*lst1copy[0]
for i in range(N):
  n=lst1.index(lst1copy[i])
  L.append(L[i]+lst1[n]*lst2[n])
  S.append(S[i]+lst2[n])
import bisect
num=bisect.bisect_left(L,A)
if M==S[num]:
  print(L[num])
else:
  print(L[num-1]+(M-S[num-1])*lst1copy[num-1])

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
dict = {}
for i in range(N):
	A, B = map(int, input().split())
	dict[A] = B
dict_sorted = sorted(dict.items())
sum = 0
ans = 0
for i in dict_sorted:
	k = i[0]
	v = i[1]
	ans = k * v + ans
	sum = sum + v
	if sum >= M:
		break
a = sum - M
ans = ans - a*k
print(ans)

Submission status: Wrong Answer

Solution code:
N,M =map(int,input().split())
List=[[int(j) for j in input().split()] for i in range(N)]
num_dict = dict()
for i in range(N):
    key = List[i][0]
    val = List[i][1]
    num_dict[key]=val
new_dict =dict()
for k,v in sorted(num_dict.items()):
    new_dict[k]=v
new_dict
M_res = 0
M_res +=M
ANS = 0

while M_res > 0:
    for i in new_dict.keys():
        if M_res < new_dict[i]:
            ANS +=  i * M_res
            M_res -=M_res
        else:
            ANS += new_dict[i] * i
            M_res -=new_dict[i]
            
        if M_res ==0:
            break
print(ANS)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
a = []
b = []
ans = 0
for i in range(n):
  aa, bb = map(int,input().split())
  a.append(aa)
  b.append(bb)
ans = 0
mini = 10000000000
while(1):
  for i in range(n):
    if a[i] < mini:
      mini = a[i]
      index = i
  ans = ans + float(a[index]*min(m,b[index]))
  m = m - min(m,b[index])
  if m == 0:
    break
  a.pop(index)
  b.pop(index)
  n = n - 1
  mini = 10000000000
  
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin

N,M = map(int, input().split(' '))
shop = [stdin.readline().rstrip().split(' ') for i in range(N)]
shop = sorted(shop)

sum = 0
for i in range(N) :
  if M > int(shop[i][1]) :
    M -= int(shop[i][1])
    sum += int(shop[i][0]) * int(shop[i][1])
  elif M <= int(shop[i][1]) :
    sum += int(shop[i][0]) * M
    M = 0
    break
    
print(sum)

Submission status: Wrong Answer

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

prices = []
numdict = {}

for _ in range(n):
  price, num = map(int, input().split())
  prices.append(price)
  if price in numdict:
    numdict[price] += num
  else:
    numdict[price] = num

prices.sort()

result = 0
looped = 0

for mprice in prices:
  if numdict[mprice] <= (m - looped):
    result += mprice * numdict[mprice]
    looped += numdict[mprice]
  elif (m - looped) == 0:
    pass
  else:
    result += (m - looped) * mprice
    looped = m
  
print(result)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
A=[]
ab={}
s=0
for i in range(n):
    a,b=map(int,input().split())
    A.append(a)
    ab[a]=b
A=sorted(A)
k=0
while m>0:
    if m>=ab[A[k]]:
        m-=ab[A[k]]
        s+=ab[A[k]]*A[k]
    else:
        s+=A[k]*m
        m=0
    k+=1
print(s)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
import sys
N, M = map(int, raw_input().split())

if M <= 0:
    print 0
    sys.exit()

dic = {} # yen: many

for i in range(N):
    A, B = map(int, raw_input().split())
    dic.update({A:B})

dic = sorted(dic.items())

count = 0
yen = 0
for k, v in dic:

    if v <= M-count:
        yen += k*v
        count += v
    else:
        yen += k*(M-count)
        count += M-count
    if count == M: break

print yen

Submission status: Wrong Answer

Solution code:
li = []
need = 0
inp = [int(i) for i in input().split()]
zan = inp[1]
for k in range(inp[0]):
  li.append([int(d) for d in input().split()])
kin = [s[0] for s in li]
hon = [s[1] for s in li]
kins = sorted(kin)
for c in range(inp[0]): #安い順に
  b = [n for n, x in enumerate(kin) if x == kins[c]]
  if type(b) is int:#Bは何店舗目
    b = [b]
  for z in b:
    if hon[z] >= zan:
      need += zan*kin[z]
      zan = 0
    else:
      need += hon[z]*kin[z]
      zan = zan - hon[z]
  if zan == 0:
    break
print(need)

Submission status: Wrong Answer

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

A = [x[0] for x in a]
A_sorted = sorted(A)
ans = 0
nokori = M
for c in A_sorted:
	for j in range(N):
		if c == A[j]:
			ans += A[j]*min(a[j][1],nokori)
			nokori -= min(a[j][1],nokori)
		if nokori <= 0:
			print(ans)
			exit()

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
dict = {}
for i in range(N):
	A, B = map(int, input().split())
	dict[A] = B
dict_sorted = sorted(dict.items())
sum = 0
ans = 0
for i in dict_sorted:
	k = i[0]
	v = i[1]
	ans = k * v + ans
	sum = sum + v
	if sum > M:
		break
a = sum - M
ans = ans - a*k
print(ans)

Submission status: Wrong Answer

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

An = sorted(A)
Bn = []
for i in range(N):
    Bn.append(B[A.index(An[i])])
i=0

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

Submission status: Wrong Answer

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()
  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: Wrong Answer

Solution code:
N, M = map(int, input().split())
AB = {}
for n in range(N):
    a, b = list(int(x) for x in input().split())
    AB[a] = b
yen = 0
AB = sorted(AB.items())
for a, b in AB:
    if b <= M:
        yen += a*b 
        M -= b
    else:
        yen += a*M
        M = 0
print(yen)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
A = []
B = []
for i in range(n):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
ans = 0
for i in range(m+1):
    a = min(A)
    B[A.index(a)] -= 1
    if B[A.index(a)] == -1:
        A.remove(a)
    else:
        ans += a
print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
A = []
for i in range(N):
	A.append(list(map(int, input().split())))
A.sort()
count = 0
nedan = 0
for s in range(N):
	count += A[s][1]
	if(count < M):
		nedan += A[s][0]*A[s][1]
	elif(count > M):
		nedan += A[s][0]*A[s][1]
		nedan -= A[s][0]*(count - M)
		print(nedan)
		exit()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
from sys import exit

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

shops = {}

for _ in range(N):
    A, B = map(int, input().split())
    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: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
N, M = map(int, raw_input().split())

dic = {} # yen: many

for i in range(N):
    A, B = map(int, raw_input().split())
    dic.update({A:B})

dic = sorted(dic.items())

count = 0
yen = 0
for k, v in dic:

    if v <= M-count:
        yen += k*v
        count += v
    else:
        yen += k*(M-count)
        count += M-count
    if count == M: break

print yen

Submission status: Wrong Answer

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

A = [x[0] for x in a]
B = [x[1] for x in a]
A_sorted = sorted(A)
ans = 0
nokori = M
for c in A_sorted:
	for j in range(N):
		if c == A[j]:
			ans += A[j]*min(B[j],nokori)
			nokori -= min(B[j],nokori)
		if nokori <= 0:
			print(ans)
			exit()

Submission status: Wrong Answer

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

A = []
B = []
for i in AB:
    a,b = i
    A.append(a)
    B.append(b)

sortA = sorted(A)

ans = 0
num = M
for i in sortA:
    ind = A.index(i)
    k = B[ind]
    if num > k:
        num -= k
        ans += i* k
    elif num == k:
        ans += i* k
        break
    else:
        ans += i * num
        break
        
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=[int(i) for i in input().split()]
min_money=[10000000000,1000000001,1000000002,1000000003,1000000004,1000000005,1000000006,1000000007,1000000008,1000000009]
min_buy=[0,0,0,0,0,0,0,0,0,0]
for i in range(n):
    a,b=[int(i) for i in input().split()]
    if a<min_money[-1]:
        min_money.append(a)
        min_money.sort()
        min_money.pop()
    if a in min_money:
        min_buy.insert(min_money.index(a),b)
        min_buy.pop()
ans=0
for i in range(len(min_buy)):
    if min_buy[i]>=m:
        ans+=min_money[i]*m
        break
    else:
        ans+=min_money[i]*min_buy[i]
        m-=min_buy[i]
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

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

cost = 0
plice_dic = {}
m = 0

for i in range(N):
    A, B = [int(i) for i in input().split()]
    if m < M: # M本に満たない
        buy = min(M - m, B) # 買えるだけ買う
        m += buy
        if A in plice_dic.keys():# A円でbuy本買った
            plice_dic[A] += buy
        else:
            plice_dic[A] = buy 
        B -= buy
    if B > 0: # まだBがある
        max_plice = max(plice_dic.keys())
        if A < max_plice: # 安かった
            buy = min(plice_dic[max_plice], B) # 買えるだけ買い足す
            plice_dic[max_plice] -= buy
            if A in plice_dic.keys():
                plice_dic[A] += buy
            else:
                plice_dic[A] = buy
            if plice_dic[max_plice] == 0:
                del plice_dic[max_plice]

print(sum(i * j for i, j in plice_dic.items()))

Submission status: Wrong Answer

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

sortkey = lambda val: val[1]
AB.sort(key=sortkey)

for i in range(N):
    for j in range(int(AB[i][1])):
        cnt += 1
        yen += AB[i][0]
        if cnt >= M:
            break
print(yen)

Submission status: Wrong Answer

Solution code:
x = [int(i) for i in input().split()]
cost = x[1]
value = 0
dic = {}
li = []
for i in range(x[0]):
  tmp = [int(j) for j in input().split()]
  li.append(tmp[0])
  dic[tmp[0]] = tmp[1]
li = sorted(li)
for i in li:
  # print('{}-{}'.format(i*dic[i], cost))
  if dic[i] <= cost:
    value += i*dic[i]
    cost -= dic[i]
  else:
    value += i*cost
    break
print(value)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
li={}
for i in range(N):
	a,b = map(int,input().split())
	li[a]=b
li=sorted(li.items())
m_sum=0
for k,v in li:
	if M==0:
		break
	else:
		if v <=M:
			M-=v
			m_sum+=k*v
		else:
			m_sum+=k*M
			M=0
print(m_sum)

Submission status: Wrong Answer

Solution code:
N, M = list(map(int, input().split()))
sh_li = []
for i in range(N):
    a, b = list(map(int, input().split()))
    sh_li.append([a, b])
sh_li.sort(key=lambda x:x[0],reverse=False)

def calc(li, m):
    total = 0
    for sh in li:
        print(sh)
        if sh[1] < m:
            total += sh[0] * sh[1]
            m -= sh[1]
        else:
            total += sh[0] * m
            return total

print(calc(sh_li, M))

Submission status: Wrong Answer

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 = defaultdict(int)
array = []
for i in range(a):
    x, y = map(int, input().split())
    d[x] = y
    array.append(x)
array.sort()


count = 0
for i in array:
    if b <= d[i]:
        count += max(b, 0) * i
        break
    else:
        t = d[i]
        b -= t
        count += t * i
print(count)

Submission status: Wrong Answer

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]
else:
    money_b = 0
print(money_a + money_b)

Submission status: Wrong Answer

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