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: Runtime Error

Solution code:
#pragma GCC optimize ("O3")
 
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <set>
#include <algorithm>
#include <numeric>
using namespace std;
 
using QWORD  = uint64_t;
using SQWORD = int64_t;
using DWORD  = uint32_t;
using SDWORD = int32_t;
using WORD   = uint16_t;
using SWORD  = int16_t;
using BYTE   = uint8_t;
using SBYTE  = int8_t;
using DOUBLE = double;
using FLOAT  = float;
 
#define MIN_SDWORD (-2147483648)
#define MAX_SDWORD (2147483647)
#define MIN_SBYTE (-128)
#define MAX_SBYTE (127)
 
#define MIN_SQWORD (0x8000000000000000)
#define MAX_SQWORD (0x7FFFFFFFFFFFFFFF)
 
#define MAX_QWORD  (0xFFFFFFFFFFFFFFFF)
#define MAX_DWORD  (0xFFFFFFFF)
#define MAX_WORD   (0xFFFF)
#define MAX_BYTE   (0xFF)
 
 
#define ArrayLength(a)  (sizeof(a) / sizeof(a[0]))
 
static inline QWORD MAX(QWORD a, QWORD b) { return a > b ? a : b; }
static inline DWORD MAX(DWORD a, DWORD b) { return a > b ? a : b; }
static inline SDWORD MAX(SDWORD a, SDWORD b) { return a > b ? a : b; }
static inline QWORD MIN(QWORD a, QWORD b) { return a < b ? a : b; }
static inline DWORD MIN(DWORD a, DWORD b) { return a < b ? a : b; }
static inline SDWORD MIN(SDWORD a, SDWORD b) { return a < b ? a : b; }
 
#define BYTE_BITS   (8)
#define WORD_BITS   (16)
#define DWORD_BITS  (32)
#define QWORD_BITS  (64)
 
using M_BOOL = bool;
#define M_TRUE (true)
#define M_FALSE (false)
#define DIVISOR (1000000007)
 
static inline void inputString(char *pcStr)
{
    char *pcCur = pcStr;
    for (;;) {
        char c = getchar();
        if (('\n' == c) || (EOF == c)) {
            break;
        }
        *pcCur = c;
        pcCur++;
    }
    *pcCur = '\0';
}
 
 
static inline SQWORD inputSQWORD(void)
{
    SQWORD sqNumber = 0;
    SQWORD sqMultiplier = 1;
    M_BOOL bRead = M_FALSE;
    for (;;) {
        char c = getchar();
        if (!bRead) {
            if ('-' == c) {
                sqMultiplier = -1;
            }
        }
        if (('0' <= c) && (c <= '9')) {
            sqNumber *= 10LL;
            sqNumber += (SQWORD)(c - '0');
            bRead = M_TRUE;
        } else {
            if (bRead) {
                return sqNumber * sqMultiplier;
            }
        }
    }
}
 
 
static inline SDWORD inputSDWORD(void)
{
    SDWORD lNumber = 0;
    SDWORD lMultiplier = 1;
    M_BOOL bRead = M_FALSE;
    for (;;) {
        char c = getchar();
        if (!bRead) {
            if ('-' == c) {
                lMultiplier = -1;
            }
        }
        if (('0' <= c) && (c <= '9')) {
            lNumber *= 10;
            lNumber += (c - '0');
            bRead = M_TRUE;
        } else {
            if (bRead) {
                return lNumber * lMultiplier;
            }
        }
    }
}
 
static inline DOUBLE inputFP(void)
{
    DOUBLE dInt = 0.0;
    DOUBLE dFrac = 0.0;
    DOUBLE dMultiplier = 1.0;
    DWORD dwFpCnt = 0;
    DOUBLE *pdCur = &dInt;
    M_BOOL bRead = M_FALSE;
    for (;;) {
        char c = getchar();
        if (!bRead) {
            if ('-' == c) {
                dMultiplier = -1;
            }
        }
        if ('.' == c) {
            pdCur = &dFrac;
        } else if (('0' <= c) && (c <= '9')) {
            (*pdCur) *= 10;
            (*pdCur) += (DOUBLE)(c - '0');
            bRead = M_TRUE;
            if (pdCur == &dFrac) {
                dwFpCnt++;
            }
        } else {
            if (bRead) {
                return dMultiplier * (dInt + dFrac / (pow((DOUBLE)10.0 , (DOUBLE)dwFpCnt)));
            }
        }
    }
}
 
int main()
{
    SDWORD lInput_N, lInput_M;
 
    lInput_N = inputSDWORD();
    lInput_M = inputSDWORD();
 
    vector<pair<SDWORD, SDWORD>> vecShops;
    for (DWORD dwIdx = 0; dwIdx < lInput_N; dwIdx++) {
        SDWORD lInput_A = inputSDWORD();
        SDWORD lInput_B = inputSDWORD();
 
        vecShops.emplace_back(make_pair(lInput_A, lInput_B));
    }
    sort(vecShops.begin(), vecShops.end());
 
    SQWORD  sqAns = 0;
    SDWORD  lRestNum = lInput_M;
    DWORD dwShopIdx = 0;
    for (dwShopIdx = 0; dwShopIdx < lInput_N; dwShopIdx++) {
        lRestNum -= vecShops[dwShopIdx].second;
        sqAns += (SQWORD)(vecShops[dwShopIdx].first) * (SQWORD)(vecShops[dwShopIdx].second);
        if (lRestNum <= 0) {
            break;
        }
    }
    sqAns += (SQWORD)lRestNum * (SQWORD)(vecShops[dwShopIdx].first);
 
    printf("%lld\n", sqAns);
 
    return 0;
}

Submission status: Runtime Error

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

def f(remain_cnt, idx):
    if remain_cnt <= AB[idx][1]:
        return remain_cnt * AB[idx][0]
    return AB[idx][0] * AB[idx][1] + f(remain_cnt - AB[idx][1], idx + 1)

print(f(M, 0))

Submission status: Runtime Error

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

def f(remain_cnt, l):
    if remain_cnt <= l[0][1]:
        return remain_cnt * l[0][0]
    return l[0][0] * l[0][1] + f(remain_cnt - l[0][1], l[1:])

print(f(M, AB))

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
sys.setrecursionlimit(10**9)
from ipykernel import kernelapp as app
N ,M = map(int, input().split())
A=[]
for _ in range(N):
    A.append(list(map(int,input().split())))
A = sorted(A, key = lambda x:x[0])
money = 0
mazai = 0
for i in range(N):
    if A[i][1] < M-mazai:
        money += A[i][0]*A[i][1]
        mazai += A[i][1]
    else:
        money += A[i][0]*(M-mazai)
        mazai += M-mazai
        print(money)
        break

Submission status: Runtime Error

Solution code:
import numpy as np
from ipykernel import kernelapp as app
N ,M = map(int, input().split())
A=[]
for _ in range(N):
    A.append(list(map(int,input().split())))
A = np.array(A)
A = A[np.argsort(A[:,0])]
money = 0
mazai = 0
for i in range(N):
    if A[i][1] < M-mazai:
        money += A[i][0]*A[i][1]
        mazai += A[i][1]
    else:
        money += A[i][0]*(M-mazai)
        mazai += M-mazai
        print(money)
        break

Submission status: Runtime Error

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

for i in range(n):
    if price+AB[i][0]*AB[i][1] <=m:
       price+=AB[i][0]*AB[i][1]
    else:
        price+=AB[i][0]*(m-sum(AB[i][0]))

print(price)

Submission status: Runtime Error

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

#Sorted by first element
X.sort(key=lambda x:x[0])
i = 0
total = 0
ans = 0

while i <= N-1:
	num += X[i][1]
	ans += X[i][0] * X[i][1]
	if num > M:
		ans -= X[i][0] * (num-M)
		break
	i += 1
print(ans)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
drink = []
cost = 0
count = 0
d_count = 0
rest = 0


for _ in range(N):
    drink.append(list(map(int, input().split())))
    drink.sorted(drink)

for i in range(N):
    cost += drink[i][0] * drink[i][1]
    d_count += drink[i][1]
    count += 1
    if d_count > M:
      break
      
cost -= drink[count-1][0] * drink[count-1][1]
d_count -= drink[count-1][1]
rest = M - d_count
cost += rest * drink[count-1][0]
print(cost)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
drink = []
cost = 0
count = 0
d_count = 0
rest = 0
 
 
for _ in range(N):
    drink.append(list(map(int, input().split())))
    drink.sorted()
 
for i in range(N):
    cost += drink[i][0] * drink[i][1]
    d_count += drink[i][1]
    count += 1
    if d_count > M:
      break
      
cost -= drink[count-1][0] * drink[count-1][1]
d_count -= drink[count-1][1]
rest = M - d_count
cost += rest * drink[count-1][0]
print(cost)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-                                                                                 
import sys, heapq                                                                                       
# ----------------------------------------------------------------                                      
# Use Solve Function                                                                                    
                                                                                                        
def solve(lines):                                                                                       
    N,M = map(int, lines.pop(0).split(' '))                                                             
    NLIST = []                                                                                          
    for i in range(N):                                                                                  
        A,B = map(int, lines.pop(0).split(' '))                                                         
        heapq.heappush(NLIST, (A, B))                                                                   
                                                                                                        
    res = 0                                                                                             
    while(True):                                                                                        
        p = heapq.heappop(NLIST)                                                                        
        if ( p[1] >= M ):                                                                               
            res += M * p[0]                                                                             
            break                                                                                       
        else:                                                                                           
            res += p[0] * p[1]                                                                          
            M -= p[1]                                                                                   
                                                                                                        
                                                                                                        
    print(res)                                                                                          
lines = contents.split('\n')                                                                            
                                                                                                        
# 2. use stdin                                                                                          
                                                                                                        
lines = [x.strip() for x in sys.stdin.readlines()]                                                      
                                                                                                        
#                                                                                                       
# solve !!                                                                                              
#                                                                                                       
solve(lines)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
X = []
for i in range(N):
    X.append(list(map(int, input().split())))
X.sort1(key=lambda x: x[0])
i = 0
num = 0
ans = 0
while i <= N - 1:
    num += X[i][1]
    ans += X[i][0] * X[i][1]
    if num > M:
        ans -= X[i][0] * (num - M)
        break
    i += 1
print(ans)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
using namespace std;
int main() {
  int n, m;
  long long ans = 0;
  cin >> n >> m;
  vector<int> a(n), b(n);
  vector<pair<int, int> > ab(n);
  for(int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  for(int i = 0; i < n; i++) {
    ab[i] = make_pair(a[i], b[i]);
  }
  sort(ab.begin(), ab.end());  
  for(int i = 0; i < n; i++) {
    int buy = min(m, ab[i].second);
    ans += buy * ab[i].first;
    m -= buy;
  }
  
  cout << ans << endl;
}

Submission status: Runtime Error

Solution code:
#coding: utf-8
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
money = 0
AB = sorted(AB, key=lambda x: x[0])
if M <= AB[0][1]:
  money += AB[0][0] * AB[0][1]
else:
  i = 0
  while M >= 0:
    money += AB[i][0] * AB[i][1]
    M -= AB[i][1]
    if M < 0:
      money += AB[i][0] * M
    i += 1
print(money)

Submission status: Runtime Error

Solution code:
#coding: utf-8
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
money = 0
AB = sorted(AB, key=lambda x: x[0])
if M <= AB[0][1]:
  money += AB[0][0] * AB[0][1]
else:
  i = 0
  while M >= 0:
    money += AB[i][0] * AB[i][1]
    M -= AB[i][1]
    if M <= 0:
      money += AB[i][0] * M
    i += 1
print(money)

Submission status: Runtime Error

Solution code:
#C - Energy Drink Collector
n,m = map(int,input().split())
ab = []
for i in range(n):
    ab.append(list(map(int, input().split())))
abSorted = sorted(ab)
sumB = 0
sumMoney = 0
while sumB + abSorted[i][1] < m:
    sumB += abSorted[i][1]
    sumMoney += abSorted[i][0] * abSorted[i][1]
sumMoney += sbSorted[i][0] * (m - sumB)
print(sumMoney)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
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
        sum += A[i]*B[i]
        count += B[i]
sum +=A[index]*(M-count)
print(sum)

Submission status: Runtime Error

Solution code:
import numpy

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(' ')
    if inData[0] in mseJ:
        mseJ[inData2[0]] = mseJ[inData[0]] + int(inData2[1])
    else:
        mseJ[inData2[0]] = int(inData2[1])
    neDanList.append(inData2[0])

neDanList = list(set(neDanList))
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: Runtime Error

Solution code:
import numpy as np
N, M, C = [int(x) for x in input().split()]
B = np.array([int(x) for x in input().split()])
A = np.array([[int(x) for x in input().split()] for _ in range(N)])
 
print(np.sum(A.dot(B) > -C))

Submission status: Runtime Error

Solution code:
import numpy as np
N, M, C = [int(x) for x in input().split()]
B = np.array([int(x) for x in input().split()])
A = np.array([[int(x) for x in input().split()] for _ in range(N)])
 
print(np.sum(A@B > -C))

Submission status: Runtime Error

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

C=[input().split() for i in range(N)]
B=[]
for i in C:
    B.append(list(map(int,i)))

B.sort()

k=0
l=0#何番目の店
m=0#その店で買う数
money=0
X=0#持ち数

while M>X:
    money+=B[0][0]*B[0][1]
    X+=B[0][1]
    if M<X:
        money-=B[0][0]*B[0][1]
        X-=B[0][1]
        for x in range(B[0][1]):
            m+=1
            if M=X+m:
                money+=B[0][0]*m
                print(money)
                break

    B.pop(l)#取り出す

Submission status: Runtime Error

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

C=[input().split() for i in range(N)]

k=0
l=0#何番目の店
m=0#その店で買う数
money=0
X=0#持ち数

while M>X:
    Min=int(C[0][0])
    for i in C:#どの店で買うか
        if Min>=int(i[0]):
            Min=int(i[0])
            l=k
        k+=1
    money+=int(C[l][1])*Min
    X+=m
    if X>M:
        money-=int(C[l][1])*Min
        X-=m
        for x in range(int(C[l][1])):#何個かえるか
            m+=1
            if M==X+m:#max
                money+=m*Min
                print(money)
                break


    C.pop(l)#取り出す
    #リセット
    k=0
    l=0
    m=0#その店で買う数

Submission status: Runtime Error

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

C=[input().split() for i in range(N)]

k=0
l=0#何番目の店
m=0#その店で買う数
money=0
X=0#持ち数

while M>X:
    Min=int(C[0][0])
    for i in C:#どの店で買うか
        if Min>=int(i[0]):
            Min=int(i[0])
            l=k
        k+=1
    money+=int(C[l][1])*Min
    X+=m
    if X>M:
        for x in range(int(C[l][1])):#何個かえるか
            m+=1
            if M==X+m:#max
                money+=m*Min
                print(money)
                break


    C.pop(l)#取り出す
    #リセット
    k=0
    l=0
    m=0#その店で買う数

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
A = []
for i in range(N):
    A.append(list(map(int, input().split())) for i in range(N))
A.sort()
sumcost = 0
k = 0
t = 0
while M-k>0:
    buy = min(M-k, A[t][1])
    sumcost += A[t][0]*buy
    k += buy
    t += 1


print(sumcost)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
A.sort()
sumcost = 0
k = 0
t = 0
while M-k>0:
    buy = min(M-k, A[t][0])
    sumcost += A[t][1]*buy
    k += buy
    t += 1


print(sumcost)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
A.sort()
sumcost = 0
k = 0
t = 0
while M-k>0:
    buy = min(M-k, A[t][0])
    sumcost += A[t][0]*buy
    k += buy
    t += 1


print(sumcost)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
A.sort()
sumcost = 0
k = 0
for i in range(M):
    if M-k>A[0][1]:
        sumcost += A[0][0]*A[0][1]
        k -= A[0][1]
        A.pop(0)
    else:
        sumcost += A[0][0]*(M-k)
        break

print(sumcost)

Submission status: Runtime Error

Solution code:
# coding: utf-8
from sys import stdin.readline as input
 
N, M = [int(i) for i in input().split()]
 
plices = [[int(i) for i in input().split()] for _ in range(N)]
 
plices.sort(key = lambda x:x[0])
 
m = 0
cost = 0
 
for i in range(N):
    if m >= M:
        break
    buy = min(M - m, plices[i][1])
    cost += plices[i][0] * buy
    m += buy
 
print(cost)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys

stdin = sys.stdin

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

N,M = read_int()

price_howmany = {}
price_list = []
for i in range(N):
    tmp = read_int()
    price_list.append(tmp[0])
    if tmp[0] in price_howmany:
        price_howmany[tmp[0]] += tmp[1]
    else:
        price_howmany[tmp[0]] = tmp[1]
price_list.sort()

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

if __name__ == "__main__":
    solve()

Submission status: Runtime Error

Solution code:
    def get_input_row():
      return [int(i) for i in input().split(" ")]
     
    inp = get_input_row()
    N = inp[0]
    M = inp[1]
    item_dict = {}
    num = 0
    for i in range(N):
      a, b = get_input_row()
      if a in item_dict:
        item_dict[a] += b
      else:
      	item_dict[a] = b
    sorted_list = [k for k in item_dict.keys()]
    sorted_list.sort()
    money = 0
    for price in sorted_list:
      if M > item_dict[price]:
        M -= item_dict[price]
        money += price * item_dict[price]
      else:
        money += price * M
        break
    print(money)

Submission status: Runtime Error

Solution code:
#!/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 = []
# 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 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)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from sys import exit

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

shops = {}

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

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

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

print(ans)

Submission status: Runtime Error

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

def pay(price):
    while count != M:
        prince += min_price * B[min_ind]
        count += 1
    return

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

price = 0
count = 0
while count != M:
    min_price = min(A)
    min_ind = A.index(min_price)
    pay(price)
    del A[min_ind]
    del B[min_ind]

print(count)

Submission status: Runtime Error

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

mseJ = sorted(mseJ.items())
neDanList = sorted(neDanList)

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

print(byMany)

Submission status: Runtime Error

Solution code:

# Your code here!
import numpy as np
N, M = (int(i) for i in input().split()) 
e = np.array([[int(i) for i in input().split()] for i in range(N)])
# print(M)
# print(e)

e = e[np.argsort(e[:, 0])]
# print(e)
# arr_index = np.argsort(arr_key)
# return arr[arr_index]
# print(e.sort())
# e = np.sort(e, axis=1)
# print(e)
aaa = np.cumsum(e, axis=0)
# print(aaa)/
# print((aaa[:,1] < M))
# print(np.sum((e[:, 1] * e[:, 0])[aaa[:,1] < M]))
asf = np.sum((e[:, 1] * e[:, 0])[aaa[:,1] < M])
# print(aaa[:,1] )
# print([aaa[:,1] < M])
# print(((aaa[:, 1] * e[:, 0])[aaa[:,1] < M]))
# print(e[:, 0])
# print(aaa[:, 1])
# print(aaa)
# print([aaa[:,1] < M])
# print((e[:, 1] * e[:, 0])[aaa[:,1] <= M])
honsuu = aaa[:,1][aaa[:,1] <= M][-1]
# print(M-honsuu)
nedan = e[:,0][aaa[:,1] > M][0]
# print( e[:,0][aaa[:,1] < M])
# print(aaa[:,1])
# print(e[:,0][aaa[:,1] >= M])
# # print(nedan = e[:,1][aaa[:,1] > M][-1])
# # print(e)
# print((M-honsuu))
# print(nedan)
print(nedan*(M-honsuu)+asf)
# print(asf)

Submission status: Runtime Error

Solution code:
from operator import itemgetter

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

a = []
R=[]
D = 0
X = 0
for i in range(N):
    a.append(list(map(int,input().split())))
if N ==1:
    Z = M*int(a[0])
    print(Z)
else:
    a.sort(key = itemgetter(0))

    for i in range(N):
        D += a[i][1]
        if D>M:
            R.append(i)
            break
    for i in range(R[0]+1):
        X += a[i][0]*a[i][1]
    Y = X-(D-M)*a[R[0]][0]
    print(Y)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[86]:


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])
l.sort()
for i in range(N):
   # min_id=l.index(min(l))
    if ct+ab[i][1]<M:
        money+=ab[i][0]*ab[i][1]
        ct+=ab[i][1]
        #l[i]=10000000000
    else:
        for i in range(ab[i][1]):
            money+=l[i]
            ct+=1
            if ct==M:
                break
print(money)


# ##

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
drink = []
cost = 0
count = 0
d_count = 0
rest = 0


for i in range(N):
    Drink = list(map(int, input().split()))
    drink.append(Drink)
    drink.sort()
    for j in range(drink[i][1]):
      d_count += 1
      cost += drink[i][0]
      if d_count == M or d_count == drink[i][1]
print(cost)

Submission status: Runtime Error

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

drink = 0
money = 0
list.sort(key = lambda x : x[0])

for i in range(n):
    
    
    if drink <= m:
        money += list[i][0] * list[i][1]
        drink += list[i][1]
    else:
        
        money -= list[i-1][0] * (drink - m)
    print(drink)
print(money)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
N,M = list(map(int,input().split()))
price_howmany = {}
price_list = []
for _ in range(N):
    tmp = list(map(int,input().split()))
    price_list.append(tmp[0])
    if tmp[0] in price_howmany:
        price_howmany[tmp[0]] += tmp[1]
    else:
        price_howmany[tmp[0]] = tmp[1]
price_list.sort()

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

Submission status: Runtime Error

Solution code:
from collections import defaultdict


num_shop, num_drink_to_buy = map(int, input().split(' '))

availability_by_price = defaultdict(lambda: 0)
for i in range(0, num_shop):
    price, availability = map(int, input().split(' '))
    availability_by_price[price] += availability

price_and_availability = list(availability_by_price.items())
price_and_availability.sort()

num_drink_more = num_drink_to_buy
cost = 0

while num_drink_more > 0:
    price, availability = price_and_availability.pop(index=0)
    
    if availability > num_drink_more:
        cost += num_drink_more * price
        num_drink_more = 0
    else:
        cost += availability * price
        num_drink_more -= availability

print(cost)
exit(0)

Submission status: Runtime Error

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: Runtime Error

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])
l.sort()
for i in range(N):
   # min_id=l.index(min(l))
    if ct+ab[i][1]<M:
        money+=ab[i][0]*ab[i][1]
        ct+=ab[i][1]
        #l[i]=10000000000
    else:
        for i in range(ab[i][1]):
            money+=l[i]
            ct+=1
            if ct==M:
                break
       # l[min_id]=100000000000
        if ct==M:
            break
print(money)


# ##

Submission status: Runtime Error

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