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: Accepted

Solution code:
n, m = map(int, input().split())
drink = []
for i in range (n):
    a, b = map(int, input().split())
    drink.append([a, b])
drink.sort(key=lambda x:x[0])
money = 0
store = 0
for i in range(m):
    money += drink[store][0]
    drink[store][1] -= 1
    if drink[store][1] == 0:
        store += 1
print(money)

Submission status: Accepted

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

ans = 0
for a, b in AB:
    if m > 0:
        ans += a * min(m, b)
        m -= min(m, b)
    else:
        break
        
print(ans)

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
shops = sorted([list(map(int,input().split())) for _ in range(n)])
rest = m
ans = 0
while rest > 0:
    shop = shops.pop(0)
    buy = min(rest, shop[1])
    ans += buy*shop[0]
    rest -= buy
print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=[]
for i in range(n):
    x,y=map(int,input().split())
    l.append([x,y])
l.sort()
ans=0
re=m
for i in range(n):
    if re-l[i][1]>0:
        ans+=l[i][0]*l[i][1]
        re-=l[i][1]
    else:
        ans+=l[i][0]*re
        break
print(ans)

Submission status: Accepted

Solution code:


n,m = map(int,raw_input().strip().split())

arr = []

for i in range(n):
    arr.append(list(map(int,raw_input().strip().split())))

arr = sorted(arr)

val = 0
co = 0
for i in range(n):
    if val+arr[i][1] < m:
        co+=arr[i][1]*arr[i][0]
        val+=arr[i][1]
    else:
        co+=arr[i][0]*(m-val)
        break
print(co)

Submission status: Accepted

Solution code:
#!venv/bin/python

import math
import numpy as np
import random
import copy
import statistics 
import bisect
import heapq
from collections import defaultdict 

N, M = [int(x) for x in input().split()]
AB = []
for _i in range(N):
    AB.append([int(x) for x in input().split()])

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

got_num = 0
total_money = 0
for ab in AB:
    price = ab[0]
    num = ab[1]
    if got_num + num <= M:
        total_money += price * num
        got_num += num
    else:
        total_money += price * (M - got_num)
        got_num = M
    if got_num >= M:
        break
print(total_money)

Submission status: Accepted

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

inputs.sort()
count = 0
ans = 0
for A, B in inputs:
    if M < B:
        print
        ans += A * M
        break
    else:
        ans += A * B
        M -= B

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))

N, M = inpl()
X = sorted([inpl() for _ in range(N)], key=lambda x: x[0])

ans = 0
for a, b in X:
    cnt = min(M, b)
    ans += a*cnt
    M -= cnt

print(ans)

Submission status: Accepted

Solution code:
import sys

N, M = map(int, input().split())
AB = []
for _ in range(N):
    a, b = map(int, input().split())
    AB.append((a, b))
AB.sort(key=lambda x: x[0])
ans = 0
num = 0
for a, b in AB:
    if num + b >= M:
        ans += a * (M - num)
        print(ans)
        sys.exit()
    ans += a * b
    num += b

Submission status: Accepted

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

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

ans = 0
for a, b in shops:
    if M > b:
        M -= b
        ans += a*b
    else:
        ans += a*M
        break

print(ans)

Submission status: Accepted

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

A = []
for _ in range(N):
    A.append(list(map(int, input().split())))

A.sort(key=lambda x: x[0])
ans = 0
num = 0
i = 0
while True:
    if M - num <= A[i][1]:
        ans += A[i][0] * (M-num)
        num = M
    else:
        ans += A[i][0] * A[i][1]
        num += A[i][1]
        i += 1
    if num == M:
        print(ans)
        break

Submission status: Accepted

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

AB.sort(key=lambda x: x[0])

ans = 0
while(M>0):
    for a,b in AB:
        if b>=M:
            ans += a*M
            M -= M
            break
        else:
            ans += a*b
            M -= b
print(ans)

Submission status: Accepted

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

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

arr = sorted(arr)

sum_count = 0
ans = 0
for i in range(N):
    sum_count += arr[i][1]
    ans += arr[i][1]*arr[i][0]
    if sum_count > M:
        sum_count -= arr[i][1]
        ans -= arr[i][1]*arr[i][0]
        ans += (M-sum_count) *arr[i][0]
        break
    else:
        pass

print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
 
A = [ list(map(int,input().split())) for _ in range(N) ]
A.sort()
ans = 0
while M > 0:
  if M >= A[0][1]:
    ans += A[0][0] * A[0][1]
    M -= A[0][1]
    del A[0]
  else:
    ans += A[0][0] * M
    M = 0
print(ans)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
L=[]
for i in range(N):
    A,B=map(int,input().split())
    L.append([A,B])
L.sort()
#print(L)

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

Submission status: Accepted

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

price = 0
cnt = 0
for info in ab:
    a, b = info
    if cnt + b >= M:
        price += (M-cnt)*a
        break
    else:
        cnt += b
        price += a*b

print(price)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key = lambda x:x[0])
s = 0
c = 0
for i in range(N):
    for j in range(AB[i][1]):
        s += AB[i][0]
        c += 1
        if c >= M:
            print(s)
            exit()

Submission status: Accepted

Solution code:
N,M = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(N)]
ab.sort(reverse=True)
cnt = 0
money = 0
while True:
    a,b = ab.pop()
    if cnt+b==M:
        money += b*a
        break
    elif cnt+b>M:
        money += (M-cnt)*a
        break
    else: #cnt+b<M
        money += b*a
        cnt += b
print(money)

Submission status: Accepted

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

Queue = sorted(Data, key=lambda a:a[0])
num = 0
ans = 0
while(M > num):
    q = Queue.pop(0)
    dif = min(q[1], M - num)
    num += dif
    ans += dif*q[0]
print(ans)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline
    n,m = map(int, input().split())
    aabb = [[0 for _ in range(2)] for _ in range(n)]
    for i in range(n):
        aabb[i][0], aabb[i][1] = map(int, input().split())
    aabb.sort(key=lambda x: x[0])
    count = 0
    for a,b in aabb:
        k = min([m,b])
        count += k*a
        m -= b
        if m <= 0:
            break
    print(count)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    C = [[A[i], B[i]] for i in range(N)]
    C.sort()
    ans = 0
    i = 0
    while True:
        if C[i][1]<M:
            M -= C[i][1]
            ans += C[i][0]*C[i][1]
        else:
            ans += C[i][0]*M
            break
        i += 1
    print(ans)

    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]" 
    B = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, A, B)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

data = sorted(data)
count = 0
res = 0
for li in data:
  if count + li[1] < M:
    res += li[0]*li[1]
    count += li[1]
  else:
    res += li[0]*(M-count)
    break

print(res)

Submission status: Accepted

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

l=sorted(l,key=lambda x:x[0])
#print(l)
ans=0
for s in l:
#    print(s,m)
    if m>s[1]:
        ans+=s[0]*s[1]
        m-=s[1]
    else:
        ans+=s[0]*m
        break
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_list_of_int():
    return [int(i) for i in input().split()]


def get_list_of_float():
    return [float(f) for f in input().split()]


def get_list_of_char():
    return list(input().strip())


def get_data(n, order=None, **kwargs):
    if not order:
        order = range(len(kwargs))
    it = iter(order)
    var, fn = zip(*sorted(sorted(kwargs.items()), key=lambda _: next(it)))

    rows = []
    for _ in range(n):
        rows.append(input().split())
    columns = zip(*rows)
    exec("global "+", ".join(var)+"\n"+"\n".join(
        v+"=list(map(fn[{}], data[{}]))".format(i, i)
        for i, v in enumerate(var)),
        globals(),
        {"fn": list(fn), "data": list(columns)}
    )
    return


# inputs
N, M = 0, 0
A, B = [], []


def set_inputs():
    global N, M, A, B
    N, M = get_list_of_int()
    get_data(N, A=int, B=int)
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    AB = sorted(zip(A, B))
    ans = 0
    cnt = 0
    for (a, b) in AB:
        if cnt + b <= M:
            ans += a * b
            cnt += b
            continue
        while cnt < M:
            ans += a
            cnt += 1
        break
    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    AB = [(a,b) for (a,b) in zip(A,B)]
    AB = sorted(AB, key=lambda ab: ab[0])
    val = 0
    for (a,b) in AB:
        if M == 0:
            break
        if M >= b:
            val += a * b
            M -= b
        else:
            val += a * M
            M = 0
    print(val)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]" 
    B = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, A, B)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
lst=input().split(" ")
N=int(lst[0])
M=int(lst[1])
cost=0
drinks=[]
for i in range(N):
    lst=input().split(" ")
    drinks.append([int(lst[0]),int(lst[1])])
drinks.sort(key=lambda x:x[0])
for d in drinks:
    if M>d[1]:
        M -= d[1]
        cost += d[0]*d[1]
    else:
        cost += d[0]*M
        break

    
print(cost)

Submission status: Accepted

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

ab = []
for n in range(N):
    ab.append(list(map(int, input().split())))

ab = sorted(ab)

now_M = 0
money = 0
for ab_i in ab:
    if M <= now_M:
        break
    elif M <= now_M + ab_i[1]:
        money += ab_i[0] * (M - now_M)
        now_M += M - now_M
    else:
        money += ab_i[0] * ab_i[1]
        now_M += ab_i[1]

print(money)

Submission status: Accepted

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

AB.sort()
result = 0
num = 0

for i in range(N):
    if num + AB[i][1] <= M:
        num += AB[i][1]
        result += AB[i][0] * AB[i][1]

    else:
        result += AB[i][0] * (M - num)
        break

print(result)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
AB=[]
for i in range(N):
    A,B=map(int,input().split())
    AB.append([A,B])
AB.sort()
money=0
for i in AB:
    a=i[0]
    b=i[1]
    for j in range(b):
        money+=a
        M-=1
        if M==0:
            break
    if M==0:
        break
print(money)

Submission status: Accepted

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

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

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

cost = 0
for a, c in arr:
    b = min(M, c)
    cost += a*b
    if M-c<=0:
        break
    else:
        M -= c
print(cost)

Submission status: Accepted

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, M = map(int, input().split())
stores = []
for _ in range(N):
    stores.append(list(map(int, input().split())))

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

ans = 0
buy = 0
for a, b in stores:
    if buy+b >= M:
        ans += a*(M-buy)
        break
    else:
        ans += a*b
        buy += b
print(ans)

Submission status: Accepted

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

li = []
for _ in range(N):
    a = [int(i) for i in input().split()]
    li.append(a)

li.sort()

p = 0
ans = 0
for i in range(N):
    if M > li[i][1]:
        M -= li[i][1]
        ans += li[i][0]*li[i][1]
    else:
        ans += li[i][0]*M
        print(ans)
        exit()

Submission status: Accepted

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

ab.sort()

ans = 0
for i in range(n):
    if(ab[i][1] >= m):
        print(ans + ab[i][0] * m)
        exit()

    ans += ab[i][0] * ab[i][1]
    m -= ab[i][1]

Submission status: Accepted

Solution code:
import bisect

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

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

abList.sort(key=lambda x:x[0])

cost = 0
for a, b in abList:
    if M > b:
        cost += a*b
        M -= b
    else:
        cost += M*a
        break
print(cost)

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    S = []
    for _ in range(N):
        a, b = map(int, input().split())
        S.append([a, b])

    S = sorted(S, key=lambda x: x[0])
    ans = 0
    for s in S:
        if s[1] >= M:
            ans += s[0] * M
            break
        else:
            ans += s[0] * s[1]
            M -= s[1]

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, M = [int(_) for _ in input().split()]
AB = sorted([[int(_) for _ in input().split()] for _ in range(N)])
count = 0
cost = 0
for a, b in AB:
    hon = min([M - count, b])
    cost += hon * a
    count += hon
    if count == M:
        break
print(cost)

Submission status: Accepted

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

cost = 0
for a,b in sorted(info_lst):
	cost += a*min(b,M)
	M -= b
	if M <= 0:
		break
print(cost)

Submission status: Accepted

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

AB = []

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


AB.sort(key=lambda x: x[0])

money = 0
goal = M

for i in range(10**5):
    if goal - AB[i][1] > 0:
        goal -= AB[i][1]
        money += AB[i][0] * AB[i][1]
    else:
        money += AB[i][0] * goal
        break

print(money)

Submission status: Accepted

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


def main():
  n, req = map(int, input().split())
  stores = [tuple(map(int, input().split())) for _ in range(n)]
  stores.sort(key=lambda x: x[0])
  money = 0
  
  for p, c in stores:
    if req == 0:
      break
    
    c = min(c, req)
    
    money += c * p
    req -= c
  
  print(money)


if __name__ == '__main__':
  main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def solve():
    N,M=map(int,sys.stdin.readline().rstrip().split())
    AB=[]
    for i in range(N):
        a,b=map(int,sys.stdin.readline().rstrip().split())
        AB.append((a,b))
    AB = sorted(AB, key=lambda e:e[0])
    ans=0
    for ab in AB:
        if M <= ab[1]:
            ans += ab[0]*M
            return ans
        else:
            ans += ab[0]*ab[1]
            M -= ab[1]

print(solve())

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
AB = []
for i in range(N):
    a, b = map(int, input().split())
    AB.append((a, b))
AB.sort()
yen = 0
for a, b in AB:
    if M - b <= 0:
        yen += a * M
        break
    yen += a*b
    M -= b
print(yen)

Submission status: Accepted

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

AB = sorted(AB)

kosu = 0
kane = 0
for a,b in AB:
    if kosu + b < M:
        kosu += b
        kane += b*a
    else:
        tmp = M - kosu
        kane += tmp*a
        break

print(kane)

Submission status: Accepted

Solution code:
from operator import itemgetter

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=itemgetter(0))

res = 0
count = 0
for a, b in AB:
    if count + b < M:
        res += a * b
        count += b
    else:
        res += (M - count) * a
        break
print(res)

Submission status: Accepted

Solution code:
#A
"""
H, W = map(int, input().split())
h, w = map(int, input().split())
print(H*W-h*W-w*H+h*w)
"""
#B
"""
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
ans = 0
ansb = 0
for i in range(n):
    ans = 0
    a = list(map(int, input().split()))
    for k in range(m):
        ans += a[k]*b[k]
    ans += c
    if ans > 0:
        ansb += 1
print(ansb)
"""
#C
n, m = map(int, input().split())
ans = []
ansnum = 0
honsuu = 0
for i in range(n):
    a = list(map(int, input().split()))
    ans.append(a)
ans.sort()
for i in ans:
    if honsuu + i[1] <= m:
        ansnum += i[0] * i[1]
        honsuu += i[1]
    else:
        ansnum += (m - honsuu) * i[0]
        break

print(ansnum)
#D

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
Inf = sorted([list(map(int,input().split())) for i in range(n)])
ans = 0
for i in range(n):
    cost = Inf[i][0]
    num = Inf[i][1]
    if m >= num:
        get = num
    else:
        get = m
    sumcost = cost*get
    ans += sumcost
    m -= get
    if m == 0:
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

A.sort()
res = 0
bought = 0

for a, b in A:
  if bought == M:
    break
  if bought + b <= M:
    res += a * b
    bought += b
  else:
    res += (M - bought) * a
    break

print(res)

Submission status: Accepted

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

items = sorted(items, key=lambda x: x[0])
cnt = 0
ans = 0
for item in items:
    a, b = item
    if cnt + b > M:
        tmp = M - cnt
        ans += a * tmp
        print(ans)
        exit()
    else:
        ans += a * b
        cnt += b
    if cnt >= M:
        print(ans)
        exit()

Submission status: Accepted

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


ans = 0
while M > 0:
    a, b = Drinks.pop()
    if M > b:
        M -= b
        ans += a * b
    else:
        ans += a * M
        break

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n,m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()

res = 0
for i in range(n):
    if m>=ab[i][1]:
        res += ab[i][0]*ab[i][1]
        m -= ab[i][1]
    else:
        res += ab[i][0]*m
        m = 0

    if m==0:
        break

print(res)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
abs = []
for i in range(n):
  a, b = map(int, input().split())
  abs.append({'price': a, 'count': b})
cnt = 0
total_price = 0

for x in sorted(abs, key=lambda x: x['price']):
  if cnt + x['count'] < m:
    cnt += x['count']
    total_price += x['count'] * x['price']
  else:
    total_price += (m - cnt) * x['price']
    break

print(total_price)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(n)]
l = sorted(l,key=lambda x:x[0])
ans = 0
i = 0
while m>=0:
    if l[i][1]>=m:
        ans += m*l[i][0]
        break
    else:
        ans += l[i][1]*l[i][0]
        m -= l[i][1]
    i+=1
print(ans)

Submission status: Accepted

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

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

A.sort()
ans = 0
for i in range(N):
    if M>A[i][1]:
        ans += A[i][0]*A[i][1]
        M -= A[i][1]
    else:
        ans += A[i][0]*M
        break
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
Di = []
for i in range(N):
    d = list(map(int, input().split()))
    Di.append(d)
Di.sort(key=lambda x: x[0])

yen = 0
num = 0
for d in Di:
    if num + d[1] >= M:
        yen += (M - num) * d[0]
        break
    num += d[1]
    yen += d[0] * d[1]
print(yen)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ab_array = [[int(x) for x in input().split()] for x in range(n)]
ab_array = sorted(ab_array, key=lambda x:x[0])
tmp = 0
res = 0
for a, b in ab_array:
    if tmp + b < m:
        tmp += b
        res += a*b
    else:
        res += (m-tmp)*a
        break
print(res)

Submission status: Accepted

Solution code:
I=lambda:list(map(int,input().split()));n,m=I();c=0
for a,b in sorted(I()for _ in[0]*n):c+=a*min(m,b);m=max(0,m-b)
print(c)

Submission status: Accepted

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

AB.sort(key=lambda x:x[0])
# print(AB)
num = 0
money = 0
for i in range(n):
    if num+AB[i][1]<m:
        num += AB[i][1]
        money += AB[i][0]*AB[i][1]
    else:
        money += (m-num)*AB[i][0]
        print(money)
        break

Submission status: Accepted

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

N, M = map(int, input().split())
AB = [[int(x) for x in input().split()] for _ in range(N)]
AB.sort()

ans = 0
rest = M
for a,b in AB:
    buy = min(rest, b)
    ans += a * buy
    rest -= buy
    if rest == 0:
        break
print(ans)

Submission status: Accepted

Solution code:


def main():
    n, m = map(int, input().split())
    data = [list(map(int, input().split())) for i in range(n)]
    count = 0
    data.sort(key=lambda x: x[0])
    ans = 0
    for i in range(n):
        if count + data[i][1] >= m:
            ans += data[i][0] * (m - count)
            break
        else:
            count += data[i][1]
            ans += data[i][0] * data[i][1]
    print(ans)




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
x = []
for _ in range(n):
    a, b = map(int, input().split())
    x.append([a, b])
x.sort()
ans = 0
for a, b in x:
    while m > 0 and b > 0:
        ans += a
        m -= 1
        b -= 1
    if m == 0:
        print(ans)
        exit(0)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
S = [[0, 0] for i in range(N)]
for i in range(N):
  S[i] = [int(x) for x in input().split()]
S.sort()
money = 0
for s in S:
  money += s[0] * min(s[1], M)
  M -= s[1]
  if M <= 0:
    break
print(money)

Submission status: Accepted

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

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

count = 0
amount = 0
for shop in ablst:
    if count + shop[1] < m:
        count += shop[1]
        amount += shop[1] * shop[0]
    else:
        for i in range(shop[1]):
            count += 1
            amount += shop[0]
            if count == m:
                print(amount)
                break
        break

Submission status: Accepted

Solution code:
def solve(N, M, ABs):
    ABs = sorted(ABs)
    ans = 0
    for a, b in ABs:
        if b < M:
            ans += a * b
            M -= b
        else:
            ans += M * a
            break
    return ans


if __name__ == "__main__":
    N, M = tuple(map(int, input().split(" ")))
    ABs = [tuple(map(int, input().split(" "))) for __ in range(N)]
    print(solve(N, M, ABs))

Submission status: Accepted

Solution code:
N, M = [int(i) for i in input().split()]
data_ls = list()
for i in range(N):
    data_ls.append([int(i) for i in input().split()])
data_ls = sorted(data_ls, key=lambda x:x[0])
_sum = 0
_sum_price = 0
for (a,b) in data_ls:
    if b > M - _sum:
        _sum_price += a * (M - _sum)
        break
    else:
        _sum_price += a * b
        _sum += b
print(_sum_price)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
l = [tuple(map(int, input().split())) for _ in range(n)]
l.sort()
tot = 0
i = 0
while m > 0:
    c = min(l[i][1], m)
    m -= c
    tot += l[i][0] * c
    i += 1
print(tot)

Submission status: Accepted

Solution code:
n,m = map(int, raw_input().split())
arr = []
for i in xrange(n):
	a,b = map(int, raw_input().split())
	arr.append((a,b))
arr.sort()
ans = 0
ptr = 0
while m > 0:
	ans += min(m,arr[ptr][1])*arr[ptr][0]
	m -= min(m, arr[ptr][1])
	ptr += 1
print ans

Submission status: Accepted

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

la = []

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

la.sort(key=lambda x:x[0])

ans = 0
ind = 0
#print(la)

while m > 0:
    if la[ind][1] == 0:
        ind += 1
    else:
        ans += la[ind][0]
        m -= 1
        la[ind][1]  -= 1
        #print(ans)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
lst = [tuple(map(int, input().split())) for _ in range(N)]
lst.sort()
ans = 0
h = 0
for shop in lst:
    if h + shop[1] < M:
        ans += shop[0] * shop[1]
        h += shop[1]
    else:
        ans += shop[0] * (M - h)
        break
print(ans)

Submission status: Accepted

Solution code:

def main():
    N,M = list(map(int,input().split()))
    a = [0]*N
    b=[0]*N
    for i in range(N):
        a[i],b[i] = list(map(int,input().split()))
    idxs = sorted(range(N),key=lambda x:a[x])
    rest=M
    ans=0
    for idx in idxs:
        ans += min(rest,b[idx])*a[idx]
        rest -= min(rest,b[idx])
        if rest==0:
            break

    print(ans)





if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
L = []
for i in range(N):
  L.append(list(map(int,input().split())))
L.sort()
s = 0
yen = 0
for j in range(N):
  if s + L[j][1] < M:
    s += L[j][1]
    yen += L[j][0]*L[j][1]
  else:
    yen += L[j][0]*(M-s)
    break
print(yen)

Submission status: Accepted

Solution code:
N,M=[int(x) for x in input().split()]
dic={}
for i in range(N):
    A,B=[int(x) for x in input().split()]
    try:
        dic[A]+=B
    except:
        dic[A]=B
        
s_dic=sorted(dic.items(), key=lambda x: x[0])

cost=0
for e in s_dic:
    if M-e[1]<0:
        cost+=e[0]*M
        break
    else:
        M-=e[1]
        cost+=e[0]*e[1]

print(cost)

Submission status: Accepted

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

AB.sort(key=lambda x: x[0])

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

ans = 0
for _ in range(N):
    A.append(list(map(int,input().split())))

A = sorted(A, key=lambda x: x[0])
# print(A)
for a in A:
    if a[1] >= M:
        ans += a[0]*M
        break
    else:
        ans += a[0]*a[1]
        M -= a[1]
        
print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key = lambda x : x[0])
ans = 0
for a, b in ab:
    ans += min(m, b) * a
    m -= b
    if m <= 0:
        break
print(ans)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
AB=[]
for n in range(N):
	AB.append(list(map(int,input().split())))
AB.sort(key=lambda x:x[0])
m=0
ans=0
i=0
while m<M:
	buy=min(M-m,AB[i][1])
	m+=buy
	ans+=AB[i][0]*buy
	i+=1
print(ans)