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 = [int(x) for x in input().split(' ')]
AB = {}
for i in range(N):
  a,b = [int(x) for x in input().split(' ')]
  AB[a] = b
  
dc = sorted(AB.items())

c = 0
m = M
for s in dc:
  d = m - s[1]
  if d >= 0:
    m -= s[1]
    c += s[0] * s[1]
    #print(m,c)
    if d == 0:
      break
  else:
    print(s[1] + d,"xx")
    c += s[0] * (s[1] + d)
    #print(d)
    break
print(c)

Submission status: Wrong Answer

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(' ')]
  AB[a] = b
  
dc = sorted(AB.items())

c = 0
m = M
for s in dc:
  d = m - s[1]
  if d > 0:
    m -= s[1]
    c += s[0] * s[1]
    #print(m,c)
  else:
    #print(s[1] + d,"xx")
    c += s[0] * (s[1] + d)
    #print(d)
    break
print(c)

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

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M = map(int, input().split())
A = []
B = []

for i in range(0, N):
    a, b = np.array(list(map(float, input().split())))
    A.append(a)
    B.append(b)

print(A)

cnt = 0
sum = 0
flag = 0
inf = float('inf')
arrayA = np.array(A)
arrayB = np.array(B)
for j in range(0, N):
    idx = A.index(min(arrayA))
    pay = arrayA[idx]
    num = arrayB[idx]
    arrayA[idx]=inf
    if cnt + num < M :
        cnt += num
        sum += pay*num
    else :
        diff = int(M - cnt)
        for t in range(0, diff):
            sum += pay
            cnt += 1
            if cnt == M :
                flag = 1
                print(int(sum))
                break
    if flag == 1:
        break

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)
print(kins)
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
      break
    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())
li = [list(map(int,input().split())) for i in range(N)]
li=sorted(li,key=lambda x: x[0])
m_sum=0
print(li)
for i in li:
	buy=min(M,i[1])
	m_sum+=i[0]*buy
	M-=buy
print(m_sum)

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

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:
	buy=min(M,v)
	m_sum+=k*buy
	M-=buy
print(m_sum)

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()):
    if M <= 0:
        break
    b = shop_dic[a]
    total += a * min(b, M)
    M -= min(b, M)
print(total)

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 * min(b, M)
        M -= min(b, M)
print(total)

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

shop = []

ans = 0

num = 0

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

print(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: 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())))
  
shop = 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(int, input().split())

shop = []

ans = 0

num = 0

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

print(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:
#!/usr/bin/env python
# -*- conding: utf-8 -*-
import numpy as np

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

min_value_index_list = np.argsort(A)

cnt = 0
result = 0
for i in range(N):
    cnt += B[min_value_index_list[i]]
    if  cnt <= M:
        result += A[min_value_index_list[i]] * B[min_value_index_list[i]]
    else:
        result += A[min_value_index_list[i]] * (cnt-M)
print(result)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- conding: utf-8 -*-
import numpy as np

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

min_value_index_list = np.argsort(A)

cnt = 0
result = 0
for i in range(N):
    if cnt+B[min_value_index_list[i]] <= M:
        result += A[min_value_index_list[i]] * B[min_value_index_list[i]]
        cnt += B[min_value_index_list[i]]
    else:
        result += A[min_value_index_list[i]] * (M-cnt)
print(result)

Submission status: Wrong Answer

Solution code:
N = list(map(int,input().split()))
drinks = [list(map(int,input().split())) for i in range(N[0])]
drinks.sort()
print(drinks)
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: 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])
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: 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[float(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: Wrong Answer

Solution code:
n,m = [int(x) for x in input().split()]
l = [list(map(int,input().split())) for _ in range(n)]
l.sort()
cost = 0
for x in range(n):
    if m == 0:
        exit()
    if l[x][1] <= m:
        cost += l[x][0]*l[x][1]
    else:
        cost += l[x][0]*m
    m -= l[x][1]
print(cost)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
dic = {}
for i in range(N):
    A, B = map(int, input().split())
    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: Wrong Answer

Solution code:
N,M = map(int, input().split())
data = [input().split() for i in range(N)]
 
data.sort()
num = 0
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: Wrong Answer

Solution code:
N, M = map(int, input().split())
n = 1
AB = []
while n <= N:
    Ai, Bi = map(int, input().split())
    AB.append([Ai, Bi])
    n += 1
AB.sort()
m = 0
for i in AB:
    a = i[0]
    b = i[1]
    for j in range(1,b + 1):
        m += a
        M -= 1
        if M == 0:
            break
        if M == 0:
            break
print(m)

Submission status: Wrong Answer

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())
print(c)
for j in c:
  if drink > dic[j]:
    money += j * dic[j]
    drink -= dic[j]
  else:
    money += j * drink
    break
print(money)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
dic ={}
for i in range(N):
  A,B =map(int,input().split())
  if A in dic.keys():
      dic[A] = dic[A] + B
  else:
      dic[A] = B
a = sorted(dic)
res = 0
b = 0
for i,s in enumerate(a):
  if b > M or b== M:
    break
  res += s*dic[s]
  b += dic[s]
res = res - (b-M)*a[i-1]
print(res)

Submission status: Wrong Answer

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

AB = {}
A = []
for i in range(N):
  data = input().split()
  A.append(int(data[0]))
  try:
    AB[int(data[0])] += int(data[1])
  except:
    AB[int(data[0])] = int(data[1])
A.sort()
money = 0
for a in A:
  if AB[a] < M:
    money += a*AB[a]
  else:
    money += a*M
    break
  M -= AB[a]
print(int(money))

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

ans = 0

for k, v in sorted(shops.items()):
    if M - v <= 0:
        ans += k * M
        break
    else:
        ans += k * v
        M -= v

print(ans)

Submission status: Wrong Answer

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

AB = {}
A = []
for i in range(N):
  data = input().split()
  A.append(int(data[0]))
  AB[int(data[0])] = int(data[1])
A.sort()
money = 0
for a in A:
  if AB[a] < M:
    money += a*AB[a]
  else:
    money += a*M
    break
  M -= AB[a]
print(int(money))

Submission status: Wrong Answer

Solution code:
N,M = map(int, input().split())
data = [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: 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 += b * i
        break
    else:
        b -= d[i][0]
        count += d[i][0] * i
    d[i].pop()
print(count)

Submission status: Wrong Answer

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

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

totals = 0
counts = 0
for k, v in sorted(drinks.items()):
    if counts + v < M:
        totals += k * v
        counts += v
    elif counts + v == M:
        totals += k * v
        break
    elif counts + v > M:
        totals += k * (M - counts)
        break
print(totals)

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])
AB = sorted(AB.items())
money = 0
for A,B in AB:
  if B < M:
    money += A*B
  elif B == M:
    money += A*B
    break
  elif B > M:
    money += A*M
    break
  M -= B
print(int(money))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
dic = {}
count = 0
goukei = 0

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

Solution code:
inData = input().split(' ')
mseCnt = int(inData[0])
mustCnt = int(inData[1])
neDanList = []
mseJ = {}
byCnt = 0
byMany = 0
for i in range(0, mseCnt):
    inData2 = input().split(' ')
    moji = int(inData2[0])
    mseJ[inData2[0]] = int(inData2[1])
    neDanList.append(inData2[0])

neDanList = sorted(neDanList)

for i in range(0, mseCnt):
    for j in range(0, int(mseJ[str(neDanList[i])])):
        if byCnt == mustCnt:
            break
        else:
            byCnt += 1
            byMany += int(neDanList[i])
    if byCnt == mustCnt:
        break

print(byMany)

Submission status: Wrong Answer

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

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

totals = 0
counts = 0
for k, v in sorted(drinks.items()):
    if counts + v <= M:
        totals += k * v
        counts += v
    elif counts + v > M:
        totals += k * (M - counts)
        break
print(totals)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
dic = {}
count = 0
goukei = 0

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

Solution code:
N, M = map(int, input().split())
dic = {}
count = 0
goukei = 0

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

Submission status: Wrong Answer

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

sum=0
count=0
a=[];b=[]
for i in range(n):
    atmp,btmp=map(int,input().split())
    a.append(atmp); b.append(btmp)


while(count<m):
    mina=min(a)
    for i in range(n):
            if a[i]==mina:
                if m-count>=b[i]:
                    sum+=a[i]*b[i]
                    count+=b[i]
                    b[i]=0
                else:
                    sum+=(m-count)*a[i]
                    print(sum)
            if b[i]<=0:
                a[i]=float('inf')

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)
x = 0
ans = 0
while x<m:
    c = min(A)
    ans += c*(B[A.index(c)])
    x += B[A.index(c)]
    if x > m:
        ans -= c*(x-m)
    A.remove(c)
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- conding: utf-8 -*-
import numpy as np

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

min_value_index_list = np.argsort(A)

cnt = 0
for i in range(len(min_value_index_list)):
    if cnt+B[min_value_index_list[i]] < M:
        result = A[min_value_index_list[i]] * B[min_value_index_list[i]]
        cnt += B[min_value_index_list[i]]
    elif cnt+B[min_value_index_list[i]] >= M:
        result = A[min_value_index_list[i]] * M
print(result)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
n,m=map(int,input().split())
a=[input().split() for i in range(n)]
#print(a)
a.sort()
ans=0
#print(a)
for i in range(n):
    m-=int(a[i][1])
    if(m<0):
        ans+=int(a[i][0])*(int(a[i][1])+m)
        break
    ans+=int(a[i][0])*int(a[i][1])
    
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
n,m=map(int,input().split())
a=[input().split() for i in range(n)]
#print(a)
a.sort()
ans=0
#print(a)
for i in range(n):
    m-=int(a[i][1])
    if(m<=0):
        ans+=int(a[i][0])*(int(a[i][1])+m)
        break
    ans+=int(a[i][0])*int(a[i][1])
    
print(ans)

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
      break
    else:
      need += hon[z]*kin[z]
      zan = zan - hon[z]
  if zan == 0:
    break
print(need)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
n,m=map(int,input().split())
a=[input().split() for i in range(n)]
print(a)
a.sort()
ans=0
#print(a)
for i in range(n):
    m-=float(a[i][1])
    if(m<=0):
        ans+=float(a[i][0])*(float(a[i][1])+m)
        break
    ans+=float(a[i][0])*float(a[i][1])
    
print(ans)

Submission status: Wrong Answer

Solution code:
N,M=(int(x) for x in input().split())
A=[0]*N
B=[0]*N
for i in range(N):
    A[i],B[i]=(int(x) for x in input().split())
K=0
T=0
Q=sorted(A)
for i in range(N):
    s=A.index(Q[i])
    if M-T<B[s]:
        K+=(M-T)*Q[i]
        break
    else:
        K+=B[s]*Q[i]
        T+=B[s]
    if T==M:
        break
print(K)

Submission status: Wrong Answer

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

temp_dict = {}

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

sort_after = sorted(temp_dict.items(), 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: 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[float(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: 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_shop_list = sorted(S.items(), 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: Wrong Answer

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
cost = 0
for n in range(0, N):
  if m >= M:
    break
  m = m + B[n]
  cost = cost + A[n] * B[n]
if m != 0:
  cost = cost - A[n] * (m - M)

print(cost)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

def C():
   NM = input().split() 
   N = int(NM[0])
   M = int(NM[1])
   A = []
   B = []
   ab_t = []
   for i in range(N):
       ab = input().split() 
       a = int(ab[0])
       b = int(ab[1])
       ab = [a,b]
       ab_t.append(ab)
   ab_sorted = sorted(ab_t, key=lambda a: a[0])
   
   money = 0
   m = M
   for x in ab_sorted:
       if x[1] < M/2:
           m -= x[1]
           money += x[1] * x[0]
           if m == 0:
               print(money)
       else:
           for y in range(x[1]):
               money += x[0]
               m -= 1
               if m == 0:
                   print(money)
           

#   def buy(a, m, money):
#       for i,x in enumerate(a):
#           print('i')
#           print(i)
#           print('x')
#           print(x)
#           if x[1] >0:
#               a[i] = a[i][1] - 1
#               money += x[0]
#               buy(a, m, money)
#               if m==0:
#                   print(money)
           
    
    

if __name__ == '__main__':
    #A())
    #B()
    C()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N, M = map(int, input().split())
t = [tuple(map(int, input().split())) for i in range(N)] 
t = sorted(t, key = lambda tt: tt[1])
n = 0
ans = 0
for a,b in t:
    if n+b < M:
        ans += a*b
        n += b
    else:
        ans += (M-n)*a
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
ab=[list(map(int,input().split())) for l in range(N)]
ct=0
money=0
l=[]
for i in range(N):
    l.append(ab[i][0])
while ct<M:
    min_id=l.index(min(l))
    if ct+ab[min_id][1]<M:
        money+=ab[min_id][0]*ab[min_id][1]
        ct+=ab[min_id][1]
    else:
        money+=l[min_id]
        ct+=1
        if ct==M:
            break
    ab[min_id][0]=100000000000
    l[min_id]=100000000000
    if ct==M:
        break
print(money)

Submission status: Wrong Answer

Solution code:
var = list(map(int, input().split()))
N = var[0]
M = var[1]

A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())
C = zip(A,B)
C = sorted(C)
A, B = zip(*C)

index = 0
count = 0
for i in range(N):
      if(count<=M):
        index = i
      count += B[0]
count = 0
sum = 0
for i in range (index):
    sum+=A[i]*B[i]
    count+=B[i]
sum +=A[index]*(M-count)
print(sum)

Submission status: Wrong Answer

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)

# for i in range(n):
#     minj = i
#     for j in range(i,n):
#         if list_A[j]<list_A[minj]:
#             minj=j
#     hokan=list_A[i]
#     list_A[i]=list_A[minj]
#     list_A[minj]=hokan
#     hokan_b=list_B[i]
#     list_B[i]=list_B[minj]
#     list_B[minj]=hokan_b

list_A.sort()
list_B.sort()

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

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


for i in range(len(AandB)):
    if(i < len(AandB) - 1):
        if AandB[i][0] > AandB[i+1][0]:
            AandB[i],AandB[i+1] = AandB[i+1],AandB[i]
sumer = 0
for i in range(N):
    kingaku = AandB[i][0]
    zyougen = AandB[i][1]

    if M - zyougen >= 0:
        M =  M - zyougen
        sumer += kingaku * zyougen
    else:
        sumer += kingaku * M
        M = 0

print(sumer)

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))
	if rest >= l2[min_index]:
		ans += (min(l1) * l2[min_index])
	else:
		ans += (min(l1) * rest)
	rest -= l2[min_index]
	if(rest <= 0):
		break
	l1.pop(min_index)

print(ans)

Submission status: Wrong Answer

Solution code:
def C():
   NM = input().split() 
   N = int(NM[0])
   M = int(NM[1])
   A = []
   B = []
   ab_t = []
   for i in range(N):
       ab = input().split() 
       a = int(ab[0])
       b = int(ab[1])
       ab = [a,b]
       ab_t.append(ab)
   ab_sorted = sorted(ab_t, key=lambda a: a[0])
   
   money = 0
   m = M
   for x in ab_sorted:
       if x[1] < M:
           m -= x[1]
           money += x[1] * x[0]
       else:
           for y in range(x[1]):
               money += x[0]
               m -= 1
               if m == 0:
                   print(money)
           

#   def buy(a, m, money):
#       for i,x in enumerate(a):
#           print('i')
#           print(i)
#           print('x')
#           print(x)
#           if x[1] >0:
#               a[i] = a[i][1] - 1
#               money += x[0]
#               buy(a, m, money)
#               if m==0:
#                   print(money)
           
    
    

if __name__ == '__main__':
    #A())
    #B()
    C()

Submission status: Wrong Answer

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

dict = {}
for i in range(0,n):
    dict[a[i]] = b[i]

l = sorted(a)


for j in range(1,n):
    if l[j] == l[j-1]:
        dict[l[j]] = dict[l[j]]+dict[l[j-1]]
        l[j-1] = -j
        dict[l[j-1]] = 0


#print(l)
#print(dict)

ex = 0
num = 0

for i in range(0,n):
    #print(l[i])
    if num + dict[l[i]] <= m:
        ex = ex + l[i] * dict[l[i]]
        num = num + dict[l[i]]
    else:
        ex = ex + l[i] * (m - num)
        num = m
    #print([ex,num])
    if num == m:
        break

print(ex)

Submission status: Wrong Answer

Solution code:
n,m = [int(x) for x in input().split()]
l = [list(map(int,input().split())) for _ in range(n)]
l.sort()
cost = 0
for x in range(n):
    for y in range(l[x][1]):
        if m == 0:
            print(cost)
            exit()
        if l[x][1] > 0:
            l[x][1] -= 1
            m -=1
            cost += l[x][0]

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

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 v<M:
		M-=v
		m_sum+=k*v
	else:
		m_sum+=k*M
		break
print(m_sum)

Submission status: Wrong Answer

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

dict = {}
for i in range(0,n):
    dict[a[i]] = b[i]

l = sorted(a)


for j in range(0,n-1):
    if l[j] == l[j-1]:
        dict[l[j]] = dict[l[j]]+dict[l[j-1]]
        l[j-1] = -j
        dict[l[j-1]] = 0


#print(l)
#print(dict)

ex = 0
num = 0

for i in range(0,n):
    #print(l[i])
    if num + dict[l[i]] <= m:
        ex = ex + l[i] * dict[l[i]]
        num = num + dict[l[i]]
    else:
        ex = ex + l[i] * (m - num)
        num = m
    #print([ex,num])
    if num == m:
        break

print(ex)

Submission status: Wrong Answer

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

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

r=M
ans=0
for z in sorted(d.items()):
  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: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 26 17:52:43 2019

@author: nakamuratakayuki
"""

N, M = tuple(map(int, input().split()))
AtoB = []
for i in range(N):
    AtoB.append(tuple(map(int, input().split())))
AtoBdict = {AtoB[i][0]:AtoB[i][1] for i in range(len(AtoB))}
A_list = [AtoB[i][0] for i in range(len(AtoB))]
A_list.sort()
cost = 0
m = 0
lastorder = 0

for i in range(len(A_list)):
    cost += A_list[i]*AtoBdict[A_list[i]]
    m += AtoBdict[A_list[i]]
    lastorder = A_list[i]
    if M <= m:
        break
while M < m:
    cost -= lastorder
    m -= 1

print(cost)

Submission status: Wrong Answer

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

dict = {}
for i in range(0,n):
    dict[a[i]] = b[i]

l = sorted(a)

'''
for j in range(0,n-1):
    if l[j] == l[j-1]:
        dic[l[j]] = dic[l[j]]+dic[l[j-1]]
        l[j-1] = -j
        dic[l[j-1]] = 0
'''

#print(l)
#print(dict)

ex = 0
num = 0

for i in range(0,n):
    #print(l[i])
    if num + dict[l[i]] <= m:
        ex = ex + l[i] * dict[l[i]]
        num = num + dict[l[i]]
    else:
        ex = ex + l[i] * (m - num)
        num = m
    #print([ex,num])
    if num == m:
        break

print(ex)

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])
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
  else:
    money += A*(M-num)
    break
  
print(money)