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:
from collections import deque
N, M = map(int, input().split())

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

C = deque()

while len(C) < M:
    for j in range(B[A.index(min(A))]):
        C.append(min(A))
    A.remove(min(A))

C = sorted(C)
print(sum(C[:M]))

Submission status: Wrong Answer

Solution code:
from collections import deque
N, M = map(int, input().split())

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

C = deque()

while len(C) < M:
    for j in range(B[A.index(min(A))]):
        C.append(min(A))
    A.remove(min(A))

C = sorted(C)
print(C)
print(sum(C[:M]))

Submission status: Wrong Answer

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

n, m = map(int, input().split())
c = []
for i in range(n):
    a, b = map(int, input().split())
    c += [min(a,m)]*b
c.sort()
print(sum(c[:m]))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split()) #N...ken M..hon
A=[list(map(int,input().split())) for i in range(N)]
A=sorted(A) #A...en B..hon
print(A)
price=0
num=0
for i in range(N):
    if num+A[i][1]<M:
        price+=A[i][0]*A[i][1]
        num+=A[i][1]
    elif num<M and num+A[i][1]>=M:
        price+=A[i][0]*(M-num)
        break
    else:
        break
print(price)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
AB=list(list(map(int,input().split())) for _ in range(N))
A=[]
B=[]
for i in range(N):
    A.append(AB[i][0])
    B.append(AB[i][1])
p=0
ans=0
for j in sorted(A):
    if M-B[A.index(j)]>0:
        M=M-B[A.index(j)]
        ans+=j*B[A.index(j)]
    else:
        ans+=j*M
        break
print(ans)

Submission status: Wrong Answer

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

count = 0
buy = 0
for a, b in ab:
    print(a,b)
    for i in range(b):
        buy += a
        count += 1

        if count >= m:
            print(buy)
            exit()

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB_dct = {}
for ii in sorted(AB):
    AB_dct[ii[0]] = ii[1]

total_drink = 0
total_pay = 0
for key, value in AB_dct.items():
    total_drink += value
    
    if M < total_drink:
        total_pay += key * (M - total_drink + value)
        break
    else:
        total_pay += value * key
        
print(int(total_pay))

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB_dct = {}
for ii in sorted(AB):
    AB_dct[ii[0]] = ii[1]
total_drink = 0
total_pay = 0

for key, value in AB_dct.items():
    total_drink += value
    
    if M < total_drink:
        total_pay += key * (M - total_drink + value)
        break
    else:
        total_pay += value * key
        
print(total_pay)

Submission status: Wrong Answer

Solution code:
n,m = list(map(int,input().split()))
a = []
b = []
for i in range(n):
    x,y = list(map(int,input().split()))
    a.append(x)
    b.append(y)
count = 0

while True:
    mi = min(a)
    print(mi,"mi")
    if m - b[a.index(min(a))] > 0 : # Bi本買う
        m = m-b[a.index(min(a))]
        count += b[a.index(min(a))] * min(a)
        
    elif m - b[a.index(min(a))] == 0:
        count += m * min(a)
        
        break
    else:
        count += m * min(a)
        break
    d = a.index(min(a))
    del a[d]
    del b[d]

print(count)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split(" "))
a = []
b = []
for i in range(n):
    temp = list(map(int,input().split(" ")))
    a.append(temp[0])
    b.append(temp[1])

sort_a = sorted(set(a))
money = 0

for ai in sort_a:
    ind = [i for i, x in enumerate(a) if x == ai]
    print(ind)
    for i in ind:
        x = min(m,b[i])
        m = m - x
        money = money + a[i]*x
    if m <= 0:
        break

print(money)

Submission status: Wrong Answer

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

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

price_list = []
stock_list = []
multi_list = []
for i in range(N):
    A, B = map(int, input().split())
    index = bisect.bisect_left(price_list, A)
    if sum(stock_list[:index]) < M:
        price_list.insert(index, A)
        stock_list.insert(index, B)
        multi_list.insert(index, A*B)

stock_list.pop()
rest = M - sum(stock_list)
multi_list.pop()
ans = sum(multi_list) + rest * price_list[-1]
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
x = [[0,0] for j in range(n)]
for j in range(n):
    x[j] = [int(k) for k in input().split()]
y = [x[j][0] for j in range(n)]
z = [x[j][1] for j in range(n)]
u = y[:]
u.sort()
v = [z[y.index(u[j])] for j in range(n)]
for j in range(n):
    m = m - v[j]
    if m <= 0:
        p = j
        break
if p == 0:
    print(m*u[0])
else:
    money = 0
    for j in range(p):
        money = money + u[j] * v[j]
    money = money + (m + v[p]) * u[p]
    print(money)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
x = [[0,0] for j in range(n)]
for j in range(n):
    x[j] = [int(k) for k in input().split()]
y = [x[j][0] for j in range(n)]
z = y[:]
z.sort()
count = 0
l = 0
while m > 0:
    m = m - x[y.index(z[l])][1]
    l = l + 1
    count = count + 1 
money = 0
for j in range(count - 1):
    money = money + x[y.index(z[j])][1] * x[y.index(z[j])][0]
money = money + (m + x[y.index(z[count-1])][1])* x[y.index(z[count-1])][0]
print(money)

Submission status: Wrong Answer

Solution code:
n,m  = map(int,input().split()) 
z = []
for i in range(n):
  a,b = list(map(int,input().split()))
  z.append((a,b))  
z = sorted(z)
print(z)
sum = 0
for a,b in z:
  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()) 
z = []
for i in range(n):
  a,b = list(map(int,input().split()))
  z.append((a,b))  
z = sorted(z)
sum = 0
for a,b in z:
  if b <= m:
    sum += a * b
    m -= b
  else:
    sum += a * m
print(sum)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
lst = [[]]*n
num = 0
price = 0

for i in range(n):
    lst[i] = list(map(int, input().split()))
lst.sort(key=lambda x:x[0])

for i in range(n):
    if num + lst[i][1] <= m:
        num += lst[i][1]
        price += lst[i][0]*lst[i][1]
    else:
        price += lst[i][0]*(m-num)
        print(price)
        exit()

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
dic={}
A=[]
for i in range(N):
    AB=list(map(int,input().split()))
    A.append(AB[0])
    dic.update({AB[0]:AB[1]})
A=sorted(A)
B=[]
for j in range(N):
    B.append(dic[A[j]])
K=M
c=-1#買いたい個数を超えるのはc番目の店
while K>0:
    K-=B[c+1]
    c+=1
total=[(B[c]+K)*A[c]]
for k in range(c):
    total.append(A[k]*B[k])
print(sum(total))

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
ori_dic = {}
for i in range(n):
    a, b = map(int, input().split())
    ori_dic[a] = b
dic = sorted(ori_dic.items(), key = lambda x : x[0])
ans = 0
amount = m
for a, b in dic:
    if b <= amount:
        ans += a*b
        amount -= b
    else:
        ans += a*amount
        break
print(ans)

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split())
e=[]
for i in range(a):
    c,d=map(int, input().split())
    e+=[[c,d]]
e.sort()
print(e)
a=i=j=0
while i < b:
    a+=(e[j][0]*e[j][1])
    i+=e[j][1]
    j+=1
print(a-((i-b)*e[j-1][0]))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
n,m=map(int,input().split())
l=[]
for i in range(n):
  a,b=map(int,input().split())
  l.append([a,b])
l.sort(key=itemgetter(1))
s=0
for j in range(n):
  s=s+l[j][0]*min(l[j][1],m)
  m=m-l[j][1]
  if m<0:
    break
print(s)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
dic={}
A=[]
for i in range(N):
    AB=list(map(int,input().split()))
    A.append(AB[0])
    dic.update({AB[0]:AB[1]})
A=sorted(A)
B=[]
for j in range(N):
    B.append(dic[A[j]])
K=M
c=0
while K>0:
    K-=B[c]
    c+=1
total=[(B[c-1]+K)*A[c-1]]
for k in range(c-1):
    total.append(A[k]*B[k])
print(sum(total))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
dic={}
A=[]
for i in range(N):
    AB=list(map(int,input().split()))
    A.append(AB[0])
    dic.update({AB[0]:AB[1]})
A=sorted(A)
B=[]
for j in range(N):
    B.append(dic[A[j]])
K=M
c=0
while K>0:
    K-=B[c]
    c+=1
total=[(B[c-1]+K)*A[c-1]]
for k in range(c-1):
    total.append(A[k]*B[k])
print(sum(total))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
A=[None]*N
B=[None]*N
for n in range(N):
    A[n],B[n]=map(int,input().split())
orderA=sorted(range(N), key=lambda k: A[k])
oAs=[A[i]*B[i] for i in orderA]
oB=[B[i] for i in orderA]
for n in range(N):
    if sum(oB[:(n+1)])>=M:
        if n>0:
            print(oAs[n-1]+(oB[n]-sum(oB[:(n+1)])+M)*A[orderA[n]])
        else:
            print((oB[n]-sum(oB[:(n+1)])+M)*A[orderA[n]])
        exit()

Submission status: Wrong Answer

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

def insertionSort(store,N,g):
    for i in range(g,N):
        tmp = store[i]
        v = store[i][0]
        j = i - g
        while j >= 0 and store[j][0] > v:
            store[j+1] = store[j]
            j = j - g
        store[j+g] = tmp

def shellSort(store,N):
    G = []
    bet = 0
    while True:
        bet = 3*bet + 1
        if bet <= N:
            G.insert(0,bet)
        else:
            break
    m = len(G)

    for i in range(m):
        insertionSort(store,N,G[i])

shellSort(store,N)

sumQ = 0
sumP = 0
for k in range(N):
    p = store[k][0]
    q = store[k][1]
    sumQ = sumQ + q
    sumP = sumP + p * q
    if M < sumQ:
        print(sumP-(sumQ-M)*p)
        break
    elif M == sumQ:
        print(sumP)
        break

Submission status: Wrong Answer

Solution code:
n, m=map(int, input().split())
x=0
a=[]
b=[]
for _ in range(n):
	s, t=map(int, input().split())
	a.append(s)
	b.append(t)
list(zip(*sorted(zip(a,b))))[1]
a.reverse()
b.reverse()
for i in range(n):
	x+=(a[i]*min(b[i],m))
	m-=b[i]
	if m<=0:
		break;
print(x)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

B = sorted(A)

cnt = 0
amount = 0
for i in range(N):
  cnt += B[i][1]
  if cnt < M:
    amount += B[i][0]*B[i][1]
  if cnt >= M:
    amount += B[i][0]*(M-cnt+B[i][1])

print(amount)

Submission status: Wrong Answer

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

array.sort(key=lambda x: x[0])
print(array)
ans = 0
cnt = 0
for i in range(N):
  #何本買うか
  buy = min([array[i][1], M-cnt])
  cnt += buy
  ans += array[i][0]*buy

print(ans)

Submission status: Wrong Answer

Solution code:
n, m=map(int, input().split())
x=0
a=[]
b=[]
for _ in range(n):
	s, t=map(int, input().split())
	a.append(s)
	b.append(t)
a.sort()
b.sort()
for i in range(n):
	x+=(a[i]*min(b[i],m))
	m-=b[i]
	if m<=0:
		break;
print(x)

Submission status: Wrong Answer

Solution code:
import sys

N, M = map(int, input().split())
lst = []
for i in range(N):
    lst += [list(map(int, input().split()))]
lst.sort()    
print (lst)
count = M
yen = 0

for i in range(N):
    yen += lst[i][0] * min(count, lst[i][1])  
    count -= min(count, lst[i][1])
#    print (count)
    if count <= 0:
        print (yen)
        sys.exit()

Submission status: Wrong Answer

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

print(ab)
ab.sort(key=lambda ab:(ab[0]))
print(ab)
s = 0
cnt = 0
for i in range(M):
    s += ab[cnt][0]
    if ab[cnt][1]>1:
        ab[cnt][1] -= 1
    else:
        cnt += 1
print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

data =[]
for i in range(n):
    tmp_a, tmp_b = list(map(int, input().split()))
    data.append((tmp_a, tmp_b))


total =0
cost = 0
for a, b in sorted(data, key=lambda x:x[0]):
    print(a, b)
    if total + b < m:
        total += b
        cost += a*b
    else:
        cost += a*(m-total)
        break
print(cost)

Submission status: Wrong Answer

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

data =[]
for i in range(n):
    tmp_a, tmp_b = list(map(int, input().split()))
    data.append((tmp_a, tmp_b))


total =0
cost = 0
for a, b in sorted(data, key=lambda x:x[0]):
#     print(a, b)
    if total + b < m:
        total += b
        cost += a*b
    else:
        cost += a*(m-total)
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


drink_num = 0
drink_cost = 0
for key, value in sorted(dic.items()):
    if drink_num + value >= M:
        drink_cost += (M - drink_num)*key
        break
    else:
        drink_cost += key*value
        drink_num += value

print(drink_cost)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N,M = [int(x) for x in input().split()]
ABdict = {}
for _ in range (N):
    A,B = [int(x) for x in input().split()]
    if A in ABdict.keys():
        ABdict[A] += B
    else:
        ABdict[A] = B

print(ABdict)
dct = sorted(ABdict.items())
ls = []
ans = 0
for i in dct:
    if M >= 0:
        ans += min(M,i[1])*i[0]    
        M -= i[1]  

print(ans)

Submission status: Wrong Answer

Solution code:
n,m= map(int, input().split())
x = {}
for i in range(n):
    a,b = map(int, input().split())
    if a not in x:
        x[a] = b
    else:
        x[a] += b
s = sorted(x.keys())
ans = 0
c = 0
for ss in s:
    while x[ss] >0:
        ans += ss
        c += 1
        x[ss] -=1
        if c == m:
            break
print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split(" "))
stores = []

for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    stores.append((Ai, Bi))    

price = 0
for a, b in stores:
    if M <= b:
        price += a * M
        break
    else:
        price += a * b
        M -= b
print(price)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split(" "))
stores = dict()
keys = []
p = 10000000000

for i in range(N):
    if p==1 and stores[p] >= M:
      break
    Ai, Bi = map(int, input().split(" "))
    if Ai in stores:
        stores[Ai] += Bi
    else:
        stores[Ai] = Bi
    keys.append(Ai)
    #p = min(p, Ai)


price = 0
for i in sorted(keys):
    if M <= stores[i]:
        price += i * M
        break
    else:
        price += i * stores[i]
        M -= stores[i]

print(price)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split(" "))
stores = []
can_buy = False
for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    print(Ai, Bi)
    if can_buy and Ai > stores[-1][0]:
        continue
    stock = 0
    last_idx = -1
    tg_idx = -1
    for idx, s in enumerate(stores):
        if s[0] > Ai and tg_idx == -1:
            stock += Bi
            tg_idx = idx
        if stock < M:
            stock += s[1]
        else:
            last_idx = idx
            can_buy = True
            break
    if tg_idx != -1:
        stores.insert(tg_idx, (Ai, Bi))
    else:
        stores.append((Ai, Bi))
    if last_idx != -1:
        stores = stores[:last_idx+1]

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

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split(" "))
stores = []
can_buy = False
for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    if can_buy and Ai > stores[-1][0]:
        break
    stock = 0
    last_idx = -1
    tg_idx = -1
    for idx, s in enumerate(stores):
        if s[0] > Ai and tg_idx == -1:
            stock += Bi
            tg_idx = idx
        if stock < M:
            stock += s[1]
        else:
            last_idx = idx
            can_buy = True
            break
    if tg_idx != -1:
        stores.insert(tg_idx, (Ai, Bi))
    else:
        stores.append((Ai, Bi))
    if last_idx != -1:
        stores = stores[:last_idx+1]

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

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split(" "))
stores = []
price = 0
for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    stock = 0
    unuse = False
    tg_idx = -1
    price = 0
    for idx, s in enumerate(stores):
        if s[0] > Ai and tg_idx == -1:
            tg_idx = idx
            price += Ai*(Bi if M - stock > Bi else M - stock)
            stock += s[1]    
        if stock <= M:
            price += s[0]*(s[1] if M - stock > s[1] else M - stock)
            stock += s[1]
        else:
            unuse = True
    
    if tg_idx != -1:
        stores.insert(tg_idx, (Ai, Bi))
    else:
        stores.append((Ai, Bi))
    if unuse:
        stores = stores[:-1]

print(price)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split(" "))
stores = []
for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    tg_idx = -1
    for idx, s in enumerate(stores):
        if s[0] > Ai:
            tg_idx = idx
            break
    if tg_idx != -1:
        stores.insert(tg_idx, (Ai, Bi))
    else:
        stores.append((Ai, Bi))

    stock = 0
    unuse_idx = 0
    for idx, s in enumerate(stores):
        if stock <= M:
            stock += s[1]
        else:
            unuse_idx = idx
    if unuse_idx != -1:
        stores = stores[:unuse_idx]

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split());dd,d,ans={},{},0
for i in range(n):
  a,b=map(int,input().split())
  if a in dd:dd[a]+=b
  else:dd[a]=b
for i,j in sorted(dd.items()):d[i]=j
for i in d:
  if d[i]<=m:
    ans+=i*d[i]
    m-=d[i]
  else:
    ans+=i*m
    m=0
  if m<=0:break
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split());dd,d,ans={},{},0
for i in range(n):
  a,b=map(int,input().split())
  if a in dd:dd[a]+=b
  else:dd[a]=b
for i,j in sorted(dd.items()):d[i]=j
for i in d:
  if d[i]<=m:
    ans+=i*d[i]
    m-=d[i]
  else:
    ans+=i*m
    m=0
  if m==0:break
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split());dd,d,ans={},{},0
for i in range(n):
  a,b=map(int,input().split())
  if a in dd:dd[a]+=b
  else:dd[a]=b
for i,j in sorted(dd.items()):d[i]=j
for i in d:
  if d[i]<=m:
    ans+=i*d[i]
    m-=d[i]
  else:
    a+=i*m
    m=0
  if m==0:break
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,M = map(int, input().split())
A = np.zeros(N)
B = np.zeros(N)
for _ in range(N):
    a, b = map(int, input().split())
    A[_] = a
    B[_] = b
sume = 0
while M > 0:
    tmp = A.argmin()#greed
    tmp2 = min(M,B[tmp]) #buy
    sume += A[tmp] * tmp2
    M -=  tmp2
    print(A[tmp])
    print(B[tmp])
    A =np.delete(A,tmp)
    B = np.delete(B,tmp)
print(int(sume))

Submission status: Wrong Answer

Solution code:
import numpy as np
N,M = map(int, input().split())
A = np.zeros(N)
B = np.zeros(N)
for _ in range(N):
    a, b = map(int, input().split())
    A[_] = a
    B[_] = b
sume = 0
while M > 0:
    tmp = A.argmin()#greed
    tmp2 = min(M,B[tmp]) #buy
    sume += A[tmp] * tmp2
    M -=  tmp2
    A[tmp] = 10**9+1
print(sume)

Submission status: Wrong Answer

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

A_B_AB_list = []
for i in range(N):
    A,B = map(int,input().split())
    A_B_AB = [A,B,A*B]
    A_B_AB_list.append(A_B_AB)
A_B_AB_list.sort()
B_sums = [0]*(N+1)
AB_sums = [0]*(N+1)
for i in range(N):
    B_sums[i+1] = B_sums[i] + A_B_AB_list[i][1]
    AB_sums[i+1] = AB_sums[i] + A_B_AB_list[i][2]
for i in range(1,N+1):
    if B_sums[i] > M:
        amari = M - B_sums[i-1] 
        ans = AB_sums[i-1] + amari*A_B_AB_list[i-1][0]
        print(ans)
        break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,M = list(map(int,input().split()))
A = [tuple(map(int,input().split())) for _ in range(N)]
sortA = sorted(A,key= lambda x: x[0])
ans = 0
for i in range(N):
    if M-sortA[i][1]>0:
        ans += sortA[i][0]*sortA[i][1]
        M = M-sortA[i][1]
    else:
        ans += M*sortA[i][0]
print(ans)

Submission status: Wrong Answer

Solution code:
N, M = [int(x) for x in input().split()]
V = [tuple(map(int, input().split())) for i in range(N)]
V.sort()

money = 0
count = 0

for a, b in V:
  if count + b < M:
    count += b
    money += a * b
  else:
    money += (M - b) * a
    break
print(money)

Submission status: Wrong Answer

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

for j in range(n):
    mini = min(a)
    
    for k in range(b[a.index(mini)]):
        ans += mini
        match += 1
        if m == match:
            break
    
    a.remove(mini)
print(ans)

Submission status: Wrong Answer

Solution code:
shop_n,desire,*l=map(int,input().split())
ans=0;
for cost,stock in sorted(zip(l[::2],l[1::2])):
  ans+=cost*min(desire,stock);
  desire-=stock;
  if desire<=0:
  	print(ans);
  	break

Submission status: Wrong Answer

Solution code:
text = input()
vals = text.split(" ")
lines = []
for i in range(int(len(vals) / 2)):
    lines.append([vals[i * 2], vals[i * 2 + 1]])

n_and_m = lines[0]
n = n_and_m[0]
m = n_and_m[1]

a_and_b = lines[1:]
a = list(map(lambda x: x[0], a_and_b))
b = list(map(lambda x:x[1], a_and_b))

tmp = []

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


remain = int(m)

price = 0
for i in range(len(a_and_b)):
    for j in range(int(a_and_b[i][1])):
        remain = remain - 1
        price = price + int(a_and_b[i][0])
        if (remain == 0):
            break
    else:
        continue
    break
print(price)

Submission status: Wrong Answer

Solution code:
import numpy as np

N,M=map(int,input().split())
a=np.zeros((N,2))
for i in range(N):
    a[i,:]=np.array([i for i in map(int,input().split())])
    
ans=0
count=0
for i in np.argsort(a[:,0]):
    count+=a[i,1]
    if count<M:
        ans+=a[i,0]*a[i,1]
    else:
        ans+=a[i,0]*(M-count+a[i,1])
        break
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()
totl=0
x=0
for j,k in a:
  if x+k<m:
    totl+=j*k
    x+=k
  else:
    totl+=j*(x+k-m)
    break
print(totl)

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()
totl=0
x=0
for j,k in a:
  if x+k<m:
    totl+=j*k
    x+=k
  else:
    totl+=j*(x-m)
    break
print(totl)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=[]
b=[]
for i in range(n):
  s,t=map(int,input().split())
  a.append(s)
  b.append(t)
c=sorted(a)
d=[0]*n
for j in range(n):
  d[j]=b[a.index(c[j])]
cnt=0
totl=0
for l in range(n):
  if cnt==m:
      print(totl)
      break
  elif cnt>m:
    if l==0:
      print(c[0]*m)
      break
    else:
      print(totl-(cnt-m)*c[l-1])
      break
  else:
    totl+=c[l]
    cnt+=d[l]

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, M= map(int, input().split())
A = []
for i in range(N):
    a = list(map(int, input().split()))
    A.append(a)
A = sorted(A)
count = 0
cost = 0
i = 0
while count < M:
    cost += A[i][0] * min(A[i][1],M-count)
    count += min(A[i][1],M-count)
        
print(cost)

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)
count = 0
cost = 0
while count < M:
    pos = A.index(min(A))
    count += min(B[pos],M-count)
    cost += A[pos] * min(B[pos],M-count)
    A.pop(pos)
    B.pop(pos)
        
print(cost)

Submission status: Wrong Answer

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

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

ans = 0
for i in range(N):
    a = sortedAB[i][0]
    b = sortedAB[i][1]
    if M == 0:
        print(ans)
        exit()
    if b <= M:
        ans += a*b
        M -= b
    else:
        ans += a*M
        M = 0

Submission status: Wrong Answer

Solution code:
N, M= map(int, input().split())
A = []
B = []
count = 0
cost = 0
for i in range(N):
    a,b = map(int, input().split())
    A.append(a)
    B.append(b)
    count += b
    cost += a * b
    while count > M:
        pos = A.index(max(A))
        if count - B[pos] > 0:
            count -= B[pos]
            cost -= A[pos] * B[pos]
            A.pop(pos)
            B.pop(pos)
        else:
            cost -= A[pos] * (M - count)
            B[pos] -= M - count
            count = M

print(cost)

Submission status: Wrong Answer

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

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

ans = 0
for i in range(N):
    a = sortedAB[i][0]
    b = sortedAB[i][1]
    if M == 0:
        print(ans)
        exit()
    if b <= M:
        M -= b
        ans += a*b
    else:
        ans += a*M

Submission status: Wrong Answer

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

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

ans = 0
for i in range(N):
    a = sortedAB[i][0]
    b = sortedAB[i][1]
    if M == 0:
        exit()
    if b <= M:
        M -= b
        ans += a*b
    else:
        ans += a*M

Submission status: Wrong Answer

Solution code:
# 2150 start

import numpy

N,M=map(int, input().split())
price = numpy.empty((N,3))
sumcan = 0
sumprice = 0
lastshop = 0

for i in range(N):
    shop_data = input().split()
    A = int(shop_data[0])
    B = int(shop_data[1])
    price[i,0]= A * B
    price[i,1] = A
    price[i,2] = B

price = price[price[:,1].argsort(),:]

for j in range(M):
    sumcan = sumcan + price[j,2]
    if sumcan < M:
        sumprice = sumprice + price[j,0]
    elif sumcan >= M:
        sumcan = sumcan - price[j,2]
        lastshop = j
        break

sumprice = sumprice + (M - sumcan)*price[lastshop,1]

print(sumprice)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split(" "))
diction={}
price,number=0,m
for i in range(n):
  a,b=map(int,input().split(" "))
  diction[a]=b
sortdic=sorted(diction.items())
for i in sortdic:
  if number>=0:
    price+=i[0]*min(i[1],number)
    number-=min(i[1],number)
    if number==0:
      break
print(price)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split(" "))
diction={}
price,number=0,m
for i in range(n):
  a,b=map(int,input().split(" "))
  diction[a]=b
sortdic=sorted(diction.items())
for i in sortdic:
  if number>0:
    price+=i[0]*min(i[1],number)
    number-=min(i[1],number)
    if number==0:
      break
print(price)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())  # N軒の店舗, M本欲しい
# 1本Ai円のドリンクをBi本まで買うことができる
ans = 0

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

# print(shop_list)

shop_list = []
for _ in range(N):
    hoge = {}
    A, B = map(int, input().split())
    hoge['price'] = A
    hoge['amount'] = B
    shop_list.append(hoge)
    hoge = {}

shop_list.sort(key=lambda x: x['price'])
# print(shop_list)
quontity = 0
money = 0
for i in range(len(shop_list)):
    money += shop_list[i]['price']*shop_list[i]['amount']
    # print('money = ', money)
    quontity += shop_list[i]['amount']
    # print('quontity = ', quontity)
    if quontity >= M:
        money -= shop_list[i]['price']*(quontity-M)

print(money)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import heapq
hq = []  

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

hq = []
AB = {}
for i in range(N):
  temp = input()
  temp = temp.split()
  AB[int(temp[0])] = int(temp[1])
  heapq.heappush(hq, (int(temp[0]), int(temp[1])))

cost = 0
amount = 0
for i in range(N):
  if amount + hq[i][1] < M:
    amount += hq[i][1]
    cost += hq[i][0]*hq[i][1]
  else:
    temp = M - amount
    cost += hq[i][0]*temp
    break
    
print(cost)