Problem: 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.

Submission attempts (in order):
#!/usr/bin/env python
# -*- conding: utf-8 -*-
import numpy as np

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
for i in li:
    buy = min(M, i[i])
    m_sum += i[0]*buy
    M -= buy
print(m_sum)
# A = []
# B = []

#     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

#     cnt += B[min_value_index_list[i]]
#     if M - cnt >= 0:
#         result += A[min_value_index_list[i]] * B[min_value_index_list[i]]
#         goal = M - cnt
#     else:
#         result += A[min_value_index_list[i]] * goal
#         break
# print(result)


#!/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)


#!/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)

#!/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]]
    print(cnt)
    if M - cnt >= 0:
        result += A[min_value_index_list[i]] * B[min_value_index_list[i]]
        goal = M - cnt
    else:
        result += A[min_value_index_list[i]] * goal
        break
print(result)


#!/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)


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
for i in li:
	buy=min(M,i[1])
	m_sum+=i[0]*buy
	M-=buy
print(m_sum)

Verdicts: Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Wrong Answer

Accepted