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:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


N, M = LI()

AB = []
for i in range(N):
    a,b = LI()
    AB.append([a, b])



# ただ安い店から買い叩いていくだけの話
AB = sorted(AB, key=lambda x:x[0])
#  print(AB)


count = 0
idx = 0
cost = 0
while count < M:
    #  print('idx', idx)
    if AB[idx][1] > M - count:
        # この店で終わりの場合
        cost += (M-count)*AB[idx][0]
        count = M
        break
    else:
        # 全部買う
        cost += AB[idx][0] * AB[idx][1]
        count += AB[idx][1]
    idx += 1

print(cost)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
shop = []
for i in range(n):
  shop.append(list(map(int, input().split())))
shop.sort()
bought = 0
cost = 0
for i in range(n):
  bought += min(m, shop[i][1])
  cost += min(m, shop[i][1]) * shop[i][0]
  m -= min(m, shop[i][1])
print(cost)

Submission status: Accepted

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

A = [[0,0] for i in range(N)]
B = [0 for j in range(N)]

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

A.sort()

money = 0
for i in range(N+1):
    if M > A[i][1]:
        M -= A[i][1]
        money += A[i][0] * A[i][1]
    else:
        for j in range(A[i][1]+1):
            if M <= j:
                money += A[i][0] * j
                print(money)
                exit()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
mise = [[int(x) for x in input().split()] for y in range(N)]
mise.sort()
m = 0
ans = 0
for val, hon in mise:
    zan = M - m
    if zan <= 0:
        break

    if zan > hon:
        m += hon
        ans += val * hon
    else:
        m += zan
        ans += zan * val

print(ans)

Submission status: Accepted

Solution code:
# C
n, m = map(int, input().split())
ab = [[int(i) for i in input().split()] for i in range(n)]
ab.sort(key=lambda x: x[0])
index = 0
ans = 0
while m > 0 and index <= n:
    if ab[index][1] <= m:
        ans += ab[index][0] * ab[index][1]
        m -= ab[index][1]
    else:
        ans += ab[index][0] * m
        m = 0
    index += 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 a:a[0] )

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


print(cost)

Submission status: Accepted

Solution code:
N,M = map(int,input().split(' '))
D = []
for i in [0]*N:
	a,b = map(int,input().split(' '))
	D.append([a,b])

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

ans = 0
for c, s in D:
	if s < M:
		M -= s
		ans += c * s
	else:
		ans += M * c
		break
print(ans)

Submission status: Accepted

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

from operator import itemgetter
ab.sort(key=itemgetter(0))  

i=0
p=0
ans=0
while p==0:
    if m>ab[i][1]:
        ans+=ab[i][1]*ab[i][0]
        m-=ab[i][1]
        i+=1
    else:
        ans+=ab[i][0]*m
        p=1

print(ans)

Submission status: Accepted

Solution code:
from operator import itemgetter


N, M = [int(v) for v in input().split()]
pairs = []
for i in range(N):
    pairs.append([int(v) for v in input().split()])
pairs.sort(key=itemgetter(0))

ans = 0
cnt = 0
for a, b in pairs:
    if cnt + b <= M:
        ans += a * b
        cnt += b
    else:
        ans += a * (M - cnt)
        cnt += M - cnt

    if cnt >= M:
        break

print(ans)

Submission status: Accepted

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

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

money = 0
buy_num = 0

while buy_num < M:
    store = AB.pop(0)
    if store[1] >= M - buy_num:
        money = money + (M - buy_num) * store[0]
        buy_num = buy_num + (M - buy_num)
    else:
        money = money + store[1] * store[0]
        buy_num = buy_num + store[1]

print(money)

Submission status: Accepted

Solution code:
import numpy as np

n,m = list(map(int, input().split()))
a = []
b = []
for k in range(n):
    aa, bb = list(map(int, input().split()))
    a.append(aa)
    b.append(bb)


a = np.array(a)
b = np.array(b)

sort = np.argsort(a)

a_sorted = a[sort]
b_sorted = b[sort]

yen = 0
num = 0

for k in range(n):
    if num < m:
        if num + b_sorted[k] > m:
            num_buy = m - num
            yen += num_buy * a_sorted[k]
            num += num_buy
            break
        else:
            num += b_sorted[k]
            yen += b_sorted[k] * a_sorted[k]
#         print(num, yen)
    else:
        break
print(yen)

Submission status: Accepted

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

Submission status: Accepted

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

for n in range(0,N):
  i = input().split(" ")
  AB.append([int(i[0]),int(i[1])])


AB.sort()

nowBuy = 0
allcost = 0

for a in AB:
  cost = a[0]
  canBuy = a[1]
  if nowBuy + canBuy > M:
    allcost += cost*(M - nowBuy)
    break
  else:
    nowBuy += canBuy
    allcost += canBuy*cost

print(allcost)

Submission status: Accepted

Solution code:
#import collections
N,M = map(int,input().split())
l = []

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

res = 0
for t in l:
    if t[1] < M:
        res += t[0]*t[1]
        M -= t[1]
    elif t[1] >= M:
        res += t[0]*M
        break
print(res)

Submission status: Accepted

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

ab.sort()
ans = 0
for tab in ab:
    if m < 0:
        break
    ans += min(tab[1], m)* tab[0]
    m -= tab[1]
print(ans)

Submission status: Accepted

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

AB = [[int(v) for v in input().split()] for _ in range(N)]

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

index = 0
ans = 0 
count = 0
while True:
  a,b = AB[index]
  if count + b  >=  M:
    ans += (M-count) * a
    break
  else:
    count += b
    ans += a * b
    
  index += 1

print(ans)

Submission status: Accepted

Solution code:
import sys
import itertools
import copy

input = sys.stdin.readline
n, m = map(int, input().split())
drink = []
for _ in range(n):
    a, b = map(int, input().split())
    drink.append([a, b])
drink.sort()
ans = 0
for i in range(n):
    num = drink[i][1]
    if num <= m:
        ans += drink[i][0] * num
        m -= num
    else:
        ans += drink[i][0] * m
        m = 0
    if m == 0:
        break
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin

N, M = [int(x) for x in stdin.readline().rstrip().split()]
d = {}
for i in range(N):
    a, b = [int(x) for x in stdin.readline().rstrip().split()]
    if a not in d:
        d[a] = 0
    d[a] += b

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

Submission status: Accepted

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

a = [list(map(int,input().split())) for i in range(n)]

a.sort()

su = 0
co = 0

for i in range(n):
    if co + a[i][1] >= m:
        su += (m - co) * a[i][0]
        break
    else:
        su += a[i][0] * a[i][1]
        co += a[i][1]
print(su)

Submission status: Accepted

Solution code:
import sys
inp = sys.stdin.readline

N, M = map(int,inp().split())
AB = sorted([list(map(int,inp().split())) for _ in range(N)], key = lambda x: x[0])

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

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(key = lambda x: x[0])
cost, rest = 0, m
for i in range(n):
    cost += min(rest, l[i][1]) * l[i][0]
    rest -= l[i][1]
    if rest <= 0:
        break
print(cost)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
AB = [[int(x) for x in input().split()] for i in range(N)]
AB = sorted(AB)
sum_drink = 0
ans = 0
for i in range(N):
  if sum_drink + AB[i][1] <= M:
    ans += AB[i][0]*AB[i][1]
    sum_drink += AB[i][1]
  else:
    ans += AB[i][0]*(M-sum_drink)
    sum_drink = M
  if sum_drink == M:
    break
print(ans)

Submission status: Accepted

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

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

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

buy_num = 0
money = 0
for cur_ab in ab_list:
    a, b = cur_ab[0], cur_ab[1]
    if b < (M - buy_num):
        buy_num += b
        money += a * b
    else:
        money += a * (M - buy_num)
        buy_num = M
        break

print(money)

Submission status: Accepted

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

AB = sorted(AB)

ans = 0
for i in range(N):
  if AB[i][1] <= M:
    M -= AB[i][1]
    ans += AB[i][0] * AB[i][1] 
  elif AB[i][1] == M:
    M -= AB[i][1]
    ans += AB[i][0] * AB[i][1] 
  else:
    ans += AB[i][0] * M
    break

print(ans)

Submission status: Accepted

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

f = []

for _ in range(n):
    # a: cost 
    # b: cans
    a, b = map(int, input().split(' '))

    f.append((a, b))

f = sorted(f)

ans = 0

for tup in f:
    if m >= tup[1]:
        ans += (tup[0] * tup[1])
        m -= tup[1]
    
    else:
        ans += m * tup[0]
        break

print(ans)

Submission status: Accepted

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

list = sorted(list,key=lambda x:x[0],reverse=False)
hon = 0
ans = 0
flag = True
for a,b in list:
    if(flag):
        for i in range(b):
            ans += a
            hon += 1
            if hon==m:
                flag=False
                break;
print(ans)

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;check = 0
for i in range(n):
    a = ab[i][0];b = ab[i][1]
    if m > check + b:ans += a*b;check += b
    elif m == check + b:ans += a*b;break
    else:ans += (m-check)*a;break
print(ans)

Submission status: Accepted

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

B = sorted(A,key=lambda x:x[0])
i = 0
price = 0
for a,b in B:
    if i+b < M:
        i += b
        price += a * b
    else:
        price += a * (M-i)
        break
print(price)

Submission status: Accepted

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

juice = sorted(overall)
count = 0
price = 0
for i in range(len(juice)):
    if count + juice[i][1] <= M:
        price += juice[i][0] * juice[i][1]
        count += juice[i][1]
    else:
        diff = M - count
        price += juice[i][0] * diff
        break
        
print(price)

Submission status: Accepted

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

a_list = []
b_list = []

for _ in range(N):
    a,b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)
    
uni = zip(a_list,b_list)
uni = sorted(uni, key=lambda x:x[0])

a_list, b_list = zip(*uni)

now = 0
money = 0
for a, b in zip(a_list, b_list):
    if M - now < b:
        kau = M -now
        now += kau
        money += a*kau
    else:
        now += b
        money += a*b
        
print(money)

Submission status: Accepted

Solution code:
from collections import defaultdict
N, M = map(int, input().split())
D = defaultdict(int)
for i in range(N):
    A, B = map(int, input().split())
    D[A] += B

ans = 0
for i in sorted(D.keys()):
    if M > D[i]:
        ans += i * D[i]
        M -= D[i]
    else:
        ans += i * M
        M -= M
    if M <= 0:
        break
print(ans)

Submission status: Accepted

Solution code:
import sys
# import bisect
# import math
# import itertools
import numpy as np


"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """この下から書いてね"""
    n, m = ip.IL()
    ab = ip.SILS(n)
    id.S(ab, 0, 0)
    ans = 0
    res = 0
    f = False
    for x in ab:
        for _ in r(x[1]):
            res += 1
            ans += x[0]
            if res == m:
                f = True
                break
        if f:
            break

    print(ans)


main()

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])
num = 0
money = 0
for i in range(N):
    if AB[i][1]+num >= M:
        money += AB[i][0]*(M-num)
        break
    num += AB[i][1]
    money += AB[i][0]*AB[i][1]
print(money)

Submission status: Accepted

Solution code:
def solve(m,ab):
    ans = 0
    for n in ab:
        if m == 0:
            break
        c = min(m,n[1])
        m -= c
        ans += c * n[0]
    return ans


def main():
    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(solve(M,ab))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# N = int(input())
# import numpy as np
N, M = map(int, input().split())
# h, w = map(int, input().split())
lis = [[0, 0]for i in range(N)]

for i in range(N):
    lis[i] = list(map(int, input().split()))
# print(lis)
lis = sorted(lis, key=lambda x: x[0])

tmp = 0
i = -1
cost = 0
while tmp < M:
    i += 1
    tmp += lis[i][1]
    cost += lis[i][0]*lis[i][1]
print(cost-lis[i][0]*(tmp-M))

Submission status: Accepted

Solution code:
(n, m) = map(int, input().split())
shops = []
for _ in range(n):
    shops.append(list(map(int, input().split())))
shops.sort(key=lambda x: x[0])

num = 0
cost = 0
for shop in shops:
    if (num + shop[1]) >= m:
        cost += shop[0] * (m - num)
        break
    num += shop[1]
    cost += shop[0] * shop[1]
print(cost)

Submission status: Accepted

Solution code:
def solve(n, m, price_list):
    rest = m
    price_list.sort()
    ans = 0
    for v, c in price_list:
        if c >= rest:
            ans += (v * rest)
            print(ans)
            exit()
        ans += (v * c)
        rest -= c

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

solve(n, m, price_list)

Submission status: Accepted

Solution code:
n, m = [int(i) for i in input().split()]
ABs = sorted([[int(i) for i in input().split()] for _ in range(n)])
ans, num = 0, 0
for a, b in ABs:
    ans += a * min(b, m - num)
    num += min(b, m - num)
    if num == m:
        break
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def main():
	N, M = map(int, input().split())
	AB = [0] * N
	for i in range(N):
		AB[i] = list(map(int, input().split()))
	AB.sort()
	MONEY = 0
	for i in range(N):
		if M == 0:
			break
		else:
			if M < AB[i][1]:
				MONEY += M * AB[i][0]
				M = 0
			else:
				M -= AB[i][1]
				MONEY += AB[i][1] * AB[i][0]
	print(MONEY)

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
n, m= map(int, input().split())
A=[]
B=[]
for i in range(n):
    t1, t2= map(int, input().split())
    A.append([t1,t2])
    #B.append(t2)
#print(A)
A=sorted(A, key=lambda x: x[0])
#print(A)
count=0
money=0
for i in A:
    if count+i[1]<m:
        count+=i[1]
        money+=i[0]*i[1]
    else:
        while count<m:
            count+=1
            money+=i[0]
    #print(money)
print(money)

Submission status: Accepted

Solution code:
""" AtCoder """

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

AB = sorted(AB)

ans = 0
i = 0
while True:
    if M <= AB[i][1]:
        ans += AB[i][0] * M
        print(ans)
        exit()
    ans += AB[i][0] * AB[i][1]
    M -= AB[i][1]
    i += 1

Submission status: Accepted

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

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])
sx = sorted(x,key=lambda x:x[0])
money = 0
i = 0
for i in range(n):
  a,b = sx[i]
  if m > b:
    money += a*b
    m -= b
  else:
    money += a*m
    print(money)
    exit()

Submission status: Accepted

Solution code:
import numpy as np
N,M =list(map(int, input().split()))
shops = []
for i in range(N):
    a,b = list(map(int, input().split()))
    shops.append((a,b))
    
cnt = 0
minp = 0
for shop in sorted(shops):
    if cnt + shop[1] >= M:
        minp += shop[0] * (M-cnt)
        break
    else:
        minp += shop[0] * shop[1]
        cnt += shop[1]
        
print(minp)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
count = 0
AB.sort(key=lambda x:x[0])
cost = 0
for a in AB:
    if M > a[1]:
        cost += a[0] * a[1]
        M -= a[1]
    else:
        cost += a[0] * M
        break
print(cost)

Submission status: Accepted

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

stores = []
for _ in range(N):
    stores.append(list(map(int, input().rstrip().split(' '))))
    
stores = sorted(stores, key=lambda x: x[0])

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

print(cost)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Mar  9 20:50:37 2019

@author: Yamazaki Kenichi
"""

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

A.sort()
counta = M
i = 0
ans = 0
while counta > 0:
    if A[i][1] < counta:
        ans += A[i][0]*A[i][1]
        counta -= A[i][1]
        i += 1
    else:
        ans += A[i][0]*counta
        counta = 0
#    print(i,counta)
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, raw_input().split())
AB = [map(int, raw_input().split()) for _ in range(N)]
AB.sort()
res = 0
for a, b in AB:
  res += a * min(M, b)
  M -= b
  if M <= 0:
    break
print res

Submission status: Accepted

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

A_B.sort(key=lambda x: x[0])
tmp = 0
ans = 0
for a, b in A_B:
    if tmp + b >= M:
        ans += a * (M - tmp)
        break
    ans += a * b
    tmp += b
print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
AB = []
Buffer = []
for i in range(N):
  Buffer = list(map(int,input().split()))
  AB.append(Buffer)
AB.sort()
cure = 0
count = 0
for i in range(M):
  if AB[cure][1] <= 0:
    cure += 1
  AB[cure][1] -=1
  count += AB[cure][0]
print(count)

Submission status: Accepted

Solution code:
n,m = map(int,raw_input().split(" "))
a = []
for x in range(n):
  q = map(int,raw_input().split(" "))
  a.append(q)

a.sort(key=lambda a:a[0])

ans = 0
now = 0

for x in range(n):
  if now + a[x][1] >= m:
    ans = ans + a[x][0] * (m-now)
    print ans
    exit(0)
  ans += a[x][0] * a[x][1]
  now += a[x][1]

Submission status: Accepted

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

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):
    z = min(ab[i][1], m)
    ans += z * ab[i][0]
    m = m - z
    if m == 0:
        break

print(ans)

Submission status: Accepted

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

AB.sort(key=lambda x: x[0])
ans = 0
for a,b in AB:
  p = b if M >= b else M
  ans += a*p
  M -= p
  if M == 0:
    print(ans)
    sys.exit()

Submission status: Accepted

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

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

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

gold = 0
for A, B in ABi:
    if M >= B:
        M -= B
        gold += A * B
    else:
        gold += A * M
        break

print(str(gold))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
drink=[]
for _ in range(n):
  drink.append(list(map(int, input().split())))
drink.sort(key=lambda x: x[0])
cnt=0
price=0
for d in drink:
  if cnt+d[1]<m:
    price+=d[0]*d[1]
    cnt+=d[1]
  else:
    price+=d[0]*(m-cnt)
    break
print(price)

Submission status: Accepted

Solution code:
import numpy as np

N,M=list(map(int,input().split()))
A=np.zeros((N,2))

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

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

i=0
count=0
cost=0
while(1):
    if count+B[i][1]<=M:
        count+=B[i][1]
        cost+=B[i][0]*B[i][1]
    elif count+B[i][1]>M:
        add=(M-count)
        count+=add
        cost+=B[i][0]*add
    if count==M:
        break
    i+=1
print(int(cost))

Submission status: Accepted

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

for i in range(n):
    cnt += a[i][1]
    ans += a[i][0] * a[i][1]
    if cnt == m:
        break
    if cnt > m:
        ans -= abs(cnt - m) * a[i][0]
        break
print(ans)

Submission status: Accepted

Solution code:
def solve(n, m, ps):
    qs = sorted(ps)
    num_bottles = 0
    req_money = 0
    for a, b in qs:
        if num_bottles >= m:
            break
        num_buy = min(m - num_bottles, b)
        req_money += a * num_buy
        num_bottles += b
    return req_money


def main():
    n, m = (int(z) for z in input().split())
    ps = [tuple(int(z) for z in input().split()) for _ in range(n)]
    res = solve(n, m, ps)
    print(res)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

cost.sort(key=lambda x:x[0])
count = 0
price = 0
for c in cost:
    if count >= m:
        break
    if count + c[1] <= m:
       price += c[0] * c[1]
       count += c[1]
    else:
       price += c[0] * (m-count)
       count = m
print(price)

Submission status: Accepted

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

result = 0
for x in e:
    if M > x[1]:
        M -= x[1]
        result += x[0] * x[1]
    else:
        result += x[0] * M
        break

print(result)

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

s = 0
for ab in AB:
    if ab[1] > M:
        s += M*ab[0]
        break
    else:
        s += ab[0]*ab[1]
        M -= ab[1]

print(s)

Submission status: Accepted

Solution code:
from operator import itemgetter
N, M = map(int, input().split())
drink = []
for i in range(N):
    Ai, Bi = map(int, input().split())
    drink.append([Ai,Bi])

drink.sort(key=itemgetter(0))
yen = 0
m = 0
for n in range(N):
    if drink[n][1]+m < M:
        m += drink[n][1]
        yen += drink[n][0]*drink[n][1]
    else:
        yen += (M-m)*drink[n][0]
        break
print(yen)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
L = [[int(j) for j in input().split()] for i in range(N)]
L = sorted(L, key=lambda x: x[0])
ans = 0
t = 0
for a, b in L:
    k = min(M - t, b)
    ans += k * a
    t += k
    if t == M:
        break
print(ans)