Problem:


Score : 300 points

Problem Statement

Hearing that energy drinks increase rating in those sites, Takahashi decides to buy up M cans of energy drinks.

There are N stores that sell energy drinks. In the i-th store, he can buy at most B_i cans of energy drinks for A_i yen (the currency of Japan) each.

What is the minimum amount of money with which he can buy M cans of energy drinks?

It is guaranteed that, in the given inputs, a sufficient amount of money can always buy M cans of energy drinks.

Constraints

All values in input are integers.

1 \leq N, M \leq 10^5

1 \leq A_i \leq 10^9

1 \leq B_i \leq 10^5

B_1 + ... + B_N \geq M

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
A_2 B_2
\vdots
A_N B_N

Output

Print the minimum amount of money with which Takahashi can buy M cans of energy drinks.

Sample Input 1

2 5
4 9
2 4

Sample Output 1

12

With 12 yen, we can buy one drink at the first store and four drinks at the second store, for the total of five drinks. However, we cannot buy 5 drinks with 11 yen or less.

Sample Input 2

4 30
6 18
2 5
3 10
7 9

Sample Output 2

130

Sample Input 3

1 100000
1000000000 100000

Sample Output 3

100000000000000

The output may not fit into a 32-bit integer type.



Sample input:
2 5
4 9
2 4


Sample output:
12

Submission status: Wrong Answer

Solution code:
#coding: utf-8
import numpy as np

n, m = map(int, raw_input().split())
a = np.zeros((n, 2), dtype=np.uint32)
for i in np.arange(n):
    a[i] = np.array(map(int, raw_input().split()))

a = a[np.argsort(a[:,0])]

cost = 0L
for i in np.arange(n):
    if(a[i][1] < m):
        cost += a[i][0] * a[i][1]
        m -= a[i][1]
    else:
        cost += a[i][0] * m
        print(cost)
        exit()

Submission status: Wrong Answer

Solution code:
#coding: utf-8
import numpy as np

n, m = map(int, raw_input().split())
a = np.zeros((n, 2), dtype=np.uint32)
for i in np.arange(n):
    a[i] = np.array(map(int, raw_input().split()))

a = a[np.argsort(a[:,0])]

cost = 0
for i in np.arange(n):
    if(a[i][1] < m):
        cost += a[i][0] * a[i][1]
        m -= a[i][1]
    else:
        cost += a[i][0] * m
        print(cost)
        exit()

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
AB = []
p = 0
for n in range(N):
    AB.append(list(map(int, input().split())))
AB.sort()
for s, b in AB:
    print('M',M)
    p += s * min(M, b)
    M -= min(M, b)
print(p)

Submission status: Wrong Answer

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

for n in range(N):
  AB.append(list(map(int, input().split())))
  print(AB)
  AB.sort()
  for s, b in AB:
    print('M',M)
    p += s * min(M, b)
    M -= min(M, b)
print(p)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
x = [list(map(int,input().split())) for i in range(n)]
x = sorted(x,key=lambda x:x[0])
t = x[0][1]
res = 0
ans = 0
for i in range(n):
    res += x[i][1]
    ans += x[i][0]*x[i][1]
    if m-res<0:
        print(ans-((res-m)*x[i][0]))
        exit()

Submission status: Wrong Answer

Solution code:

def main():
	bought = 0
	money = 0
	DrinkList = []
	N,M = map(int,input().split())
	for i in range(1,N+1) :
		a,b = map(int,input().split())
		DrinkList.append( (a,b) )
	DrinkList.sort()
	for price,drink_max in DrinkList :
		for i in range(drink_max) :
			if bought < M :
				money += price
				bought += 1
			elif bought == M :
				print(money)
				return 0
	
	
if __name__ == "__main__" :
	main()

Submission status: Wrong Answer

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

# Insert all the data into dictionary
stores = []
for _ in range(N):
  a, b = list(map(int, input().split()))
  stores.append([a,b])

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

m = 0
money = 0

for store in stores:
  money += min(store[1], M - m) * store[0]
  m += min(store[1], M - m)
  if m == M:
    break
print(money)

Submission status: Wrong Answer

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

# Insert all the data into dictionary
stores = []
while 1:
	try:
		a, b = list(map(int, input().split()))
		stores.append([a,b])
	except:
		break

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

m = 0
money = 0

for store in stores:
	money += min(store[1], M - m) * store[0]
	if m == M:
		break
print(money)
        
print(stores)

Submission status: Wrong Answer

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

# In[1]:


import numpy as np


# In[58]:


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


# In[59]:


data = np.array(data)


# In[61]:


sorted_data = data[np.argsort(data[:, 1])]


# In[63]:


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

print(ans)


# In[ ]:

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
drink = 0
max_drink = M
sum = 0
dal = {}
for n in range(N):
    A, B = map(int, input().split())
    dal[A] = B
sorted_d = sorted(dal.items())
for sd, sd2 in sorted_d:
    for bottle in range(sd2):
        if drink <= M:
            sum += sd
            drink += 1
        else:
            break
print(sum)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
drink = 0
max_drink = M
sum = 0
dal = {}
for n in range(N):
    A, B = map(int, input().split())
    dal[A] = B
sorted_d = sorted(dal.items())
for sd, sd2 in sorted_d:
    for bottle in range(sd2):
        if drink < M:
            sum += sd
            drink += 1
        else:
            break
print(sum)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
drink = 0
max_drink = M
sum = 0
dal = {}
for n in range(N):
    A, B = map(int, input().split())
    dal[A] = B
sorted_d = sorted(dal.items())
for sd, sd2 in sorted_d:
    for bottle in range(sd2):
        if drink < M:
            sum += sd
            drink += 1
        else:
            break
if not isinstance(sum, int):
    long(sum)
print(sum)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
drink = 0
max_drink = M
sum = 0
dal = {}
for n in range(N):
    A, B = map(int, input().split())
    dal[A] = B
sorted_d = sorted(dal.items())
for sd, sd2 in sorted_d:
    for bottle in range(sd2):
        if drink < M:
            sum += sd
            drink += 1
if not isinstance(sum, int):
    long(sum)
print(sum)

Submission status: Wrong Answer

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

for i in range(n):
    p.append(list(map(int,input().split())))
q = sorted(p)

a = []
b = []

for i in  range(n):
    a.append(q[i][0])
    b.append(q[i][1])
b.append(0)

s = 0
t = 0
for i in range(n):
    if t>m:
        s += a[i]*(m-t)
        break
    s += a[i]*b[i]
    t += b[i]
print(s)

Submission status: Wrong Answer

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

for i in range(n):
    p.append(list(map(int,input().split())))
q = sorted(p)

a = []
b = []

for i in  range(n):
    a.append(q[i][0])
    b.append(q[i][1])
b.append(0)
print(a)
print(b)
s = 0

for i in range(n):
    if sum(b[:i+1])>m:
        s += a[i]*(m-sum(b[:i]))
        break
    s += a[i]*b[i]
    print([s,sum(b[:i])])
print(s)

Submission status: Wrong Answer

Solution code:
import numpy as np
#N,M=2,5
#AB=np.array([[4,9],[2,4]])
N,M=map(int,input().split())
AB=np.zeros((N,2))
for i in range(N):
    AB[i,0],AB[i,1]=map(int,input().split())
AB = AB[np.argsort(AB[:, 0])]
print(AB)
numd=0
ans=0
for i in range(len(AB)):
    if numd==M:
        break
    else:
        if AB[i][1] < M-numd:
            ans+=AB[i][0]*AB[i][1]
            numd+=AB[i][1]
        else:
            ans+=AB[i][0]*(M-numd)
            numd+=M-numd
print(int(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np

N,M = map(int,input().split())
data = []
for i in range(N):
    b = list(map(int,input().split())) # data = [[cost,max_num],...]
    data.append(b)
# print(data)

# N=2 
# M=5
# data = [[4, 9], [2, 4]]
# data.sort()
npsorted = np.sort(np.array(data),axis=0)

num_drink=0
cost=0
shop_index=0
while (shop_index < N and num_drink < M):
    num_drink += npsorted[shop_index][1]
    cost += npsorted[shop_index][0]*npsorted[shop_index][1]
    shop_index += 1

# num_drink >= M by buying npsorted[shop_index-1][0]yen drink from shop_index
excess = num_drink - M
ans = cost - npsorted[shop_index-1][0] * excess
print(ans)
# print(data)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
drink = 0
max_drink = M
sum = 0
dal = {}
for n in range(N):
    A, B = map(int, input().split())
    dal[A] = B
sorted_dal = sorted(dal.keys())
for sd in sorted_dal:
    for bottle in range(dal[sd]):
        if drink < M:
            sum += sd
            drink += 1
if not isinstance(sum, int):
    long(sum)
print(sum)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
drink = 0
max_drink = M
sum = 0
dal = {}
for n in range(N):
    A, B = map(int, input().split())
    dal[A] = B
for sd in sorted(dal.keys()):
    for bottle in range(dal[sd]):
        if drink < M:
            sum += sd
            drink += 1
if not isinstance(sum, int):
    long(sum)
print(sum)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
drink = 0
max_drink = M
sum = 0
dal = {}
for n in range(N):
    A, B = map(int, input().split())
    dal[A] = B
for sd in sorted(dal.keys()):
    for bottle in range(dal[sd]):
        if drink < M:
            sum += sd
            drink += 1
print(sum)

Submission status: Wrong Answer

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

q = deque(maxlen = m)
for i in range(n):
    a, b, = map(int, input().split())
    for i in range(min(m, b)):
        if len(q) < m:
            q.appendleft(a)
        elif a <= q[0]:
            q.appendleft(a)
        else:
            continue
print(sum(q))

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
A=[input().split() for i in range(N)]
X=list(sorted(A))
price=0
drink=0
for i in range(0,N):
    if drink+int(X[i][1])<=M:
        price+=int(X[i][0])*int(X[i][1])
        drink+=int(X[i][1])
    elif M-drink<int(X[i][1]):
        price+=(M-drink)*int(X[i][0])
        break
        
print(price)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
A=[input().split() for i in range(N)]
X=list(sorted(A))
X.append(['0']*2)
price=0
drink=0
for i in range(0,N):
    if drink+int(X[i][1])<=M:
        price+=int(X[i][0])*int(X[i][1])
        drink+=int(X[i][1])
    elif M-drink<int(X[i][1]):
        price+=(M-drink)*int(X[i][0])
        break     
print(price)

Submission status: Wrong Answer

Solution code:
import re
import numpy as np

np.seterr(over='raise')

N, M = [int(item) for item in re.split(r"\s", input())]

AB = []
for _ in range(N):
    AB.append([int(item) for item in re.split(r"\s", input())])

AB = np.array(AB)
A = AB[:, 0]
B = AB[:, 1]


sorted_B = B[np.argsort(A)]
sorted_A = np.sort(A)


cumB = np.cumsum(sorted_B)
index = np.argmax(cumB > M)

if N > 1:
    total = np.sum(sorted_A[:index] * sorted_B[:index])
    total = total + (M - cumB[index - 1]) * sorted_A[index]
else:
    total = M * sorted_A[0]

print(total)

Submission status: Wrong Answer

Solution code:
import re
import numpy as np

np.seterr(over='raise')

N, M = [int(item) for item in re.split(r"\s", input())]

AB = []
for _ in range(N):
    AB.append([int(item) for item in re.split(r"\s", input())])

AB = np.array(AB)
A = AB[:, 0]
B = AB[:, 1]

print(AB)

sorted_B = B[np.argsort(A)]
sorted_A = np.sort(A)


cumB = np.cumsum(sorted_B)
index = np.argmax(cumB > M)

if N > 1:
    total = np.sum(sorted_A[:index] * sorted_B[:index])
    total = total + (M - cumB[index - 1]) * sorted_A[index]
else:
    total = M * sorted_A[0]

print(total)

Submission status: Wrong Answer

Solution code:
### coding: UTF-8
import sys

head = sys.stdin.readline()
[n, m] = head.split(" ")
n = long(n)  # 店の件数
m = long(m)  # 購入本数

amount = 0

# 店の件数分読み込み
rows = [sys.stdin.readline() for _ in range(n)]
rows.sort(key=lambda x: x.split(" ")[0])
for row in rows:
    [a, b] = row.strip().split(" ")
    ai = long(a) # 金額
    bi = long(b) # 購入可能な数量
    # 購入可能な最大数まで買う
    x = bi if m >= bi else m
    for var in range(x):
        amount += ai
    m -= x
    if m == 0:
        break

print amount

Submission status: Wrong Answer

Solution code:
### coding: UTF-8
import sys

head = sys.stdin.readline()
[n, m] = head.split(" ")
n = int(n)  # 店の件数
m = int(m)  # 購入本数

amount = 0

# 店の件数分読み込み
rows = [sys.stdin.readline() for _ in range(n)]
rows.sort()
for row in rows:
    [a, b] = row.strip().split(" ")
    an = int(a) # 金額
    bn = int(b) # 購入可能な数量
    # 購入可能な最大数まで買う
    x = bn if m >= bn else m
    amount += an * x
    m -= x
    if m == 0:
        break

print amount

Submission status: Wrong Answer

Solution code:
### coding: UTF-8
import sys

head = sys.stdin.readline()
[n, m] = head.split(" ")
n = long(n)  # 店の件数
m = long(m)  # 購入本数

amount = 0

# 店の件数分読み込み
rows = [sys.stdin.readline() for _ in range(n)]
rows.sort()
for row in rows:
    [a, b] = row.strip().split(" ")
    ai = long(a) # 金額
    bi = long(b) # 購入可能な数量
    # 購入可能な最大数まで買う
    x = bi if m >= bi else m
    amount += ai * x
    m -= x
    if m == 0:
        break

print amount

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
AB = []
ans = 0
for i in range(N):
    A,B = map(int,input().split())
    t = A,B
    AB.append(t)
    
AB.sort()

for i in range(len(AB)):
    if M > 0:
        break
    for x in range(AB[i][1]):
        if M > 0:
            ans += AB[i][0]
            M -= 1
        

print(ans)

Submission status: Wrong Answer

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

plist.sort()
print(plist)

cost=0
i = 0

while i < len(plist):
    tmp = plist[i]
    if tmp[1] < m:
        m -= tmp[1]
        cost += tmp[0] * tmp[1]
        i += 1
        continue
    else:
        cost += tmp[0] * m
        break
print(cost)

Submission status: Wrong Answer

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

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

cnt = 0
price = 0
i = 0
while cnt < m:
    price += ab[i][0] * ab[i][1]
    cnt += ab[i][1]
    if cnt > m:
        price -= ab[i][0] * (m - cnt)
        break
    i += 1

print(price)

Submission status: Wrong Answer

Solution code:
N, M = [int(i) for i in input().split()]
cost = 0
amount =0
dic ={}
for _ in range(N):
    a,b = [int(i) for i in input().split()]
    if a in dic:
        dic[a] += b
    else:
        dic[a] = b

for a,b in dic.items():
    if amount+b<=M:
        amount += b
        cost += a*b
    else:
        rest = M - amount
        cost += a*rest
        break

print(cost)

Submission status: Wrong Answer

Solution code:
N, M = [int(i) for i in input().split()]
cost = 0
amount =0
dic ={}
for _ in range(N):
    a,b = [int(i) for i in input().split()]
    dic[a] = b

for a,b in dic.items():
    if amount+b<=M:
        amount += b
        cost += a*b
    else:
        rest = M - amount
        cost += a*rest
        break

print(cost)

Submission status: Wrong Answer

Solution code:
import numpy as np
 
N, M = map(int, input().split())
A = np.zeros((N, 2))
for i in range(N):
    A[i,:] = list(map(int, input().split()))
A = A[A[:,0].argsort(), :]


count=0
price=0
for i in range(N):
    if A[0,1]>=M-count:
        price+=A[0,0]*(M-count)
        break
    else:
        price+=A[0,0]*A[0,1]
        count+=A[0,1]
    A=np.delete(A,0,0)
    
print(price)

Submission status: Wrong Answer

Solution code:
from sys import stdin

n, m = map(int, input().split())
item = sorted([stdin.readline().rstrip().split() for _ in range(n)])

bought = 0
money = 0
for i in range(len(item)) :
  price = int(item[i][0])
  num = int(item[i][1])
  if(num > m - bought) : 
    money += price*(m - bought)
    break
  else :
    money += price*num
    bought += num
print(money)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
ab = [input().split() for i in range(n)]
ab.sort()
cnt = 0
ans = 0
for i in ab:
    cnt += int(i[1])
    ans += int(i[0])*int(i[1])
    if cnt >= m:
        ans -= int(i[0])*(cnt-m)
        print(ans)
        import sys
        sys.exit()

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
ab = [input().split() for i in range(n)]
ab.sort()
cnt = 0
ans = 0
for i in ab:
    tmp = min(int(i[1]),m-cnt)
    cnt += int(i[1])
    ans += int(i[0])*tmp
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
ab = [input().split() for i in range(n)]
ab.sort()
cnt = 0
ans = 0
for i in ab:
    if cnt < m:
        ans += int(i[0])*int(i[1])
        cnt += int(i[1])
        if cnt >= m:
            ans -= int(i[0])*(cnt-m)
            print(ans)
            exit()

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

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


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

if N ==1:
    Z = M*a[0]
    print(Z)
else:
    a.sort(key = itemgetter(0))
    X = 0 
    D = 0
    var=0
    while M>D:
        D+=a[var][1]
        X+=a[var][0]*a[var][1]
        var+=1
        
    X += a[var-1][0]*(M-D)
    print(X)

Submission status: Wrong Answer

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

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

a.sort()

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

Submission status: Wrong Answer

Solution code:
import numpy as np

n, m = map(int, input().split())
a = np.zeros(n)
b = np.zeros(n)
for i in range(n):
  a[i], b[i] = map(int, input().split())
idx = np.argsort(a)
a = a[idx]
b = b[idx]
price = 0
for i in range(n):
  if m < b[i]:
    price += m * a[i]
  else:
    price += b[i] * a[i]
    m -= b[i]
print(int(price))

Submission status: Wrong Answer

Solution code:
N, M = list(map(int, input().split()))
a, b = [0 for _ in range(N)], [0 for _ in range(N)]
for i in range(N):
    a[i], b[i] = (list(map(int, input().split())))
for i in range(N-1):
    if a[i] < a[i+1]:
        pass
    else:
        tmp1 = a[i]
        tmp2 = b[i]
        a[i] = a[i+1]
        b[i] = b[i+1]
        a[i+1] = tmp1
        b[i+1] = tmp2
money=0
for i in range(N):
    money+=a[i]*b[i]
    M-=b[i]
    if M <= 0:
        break
if M == 0:
    print(money)
else:
    print(money + (a[i] * M))

Submission status: Wrong Answer

Solution code:
N, M = list(map(int, input().split()))
a, b = [0 for _ in range(N)], [0 for _ in range(N)]
for i in range(N):
    a[i], b[i] = (list(map(int, input().split())))
for i in range(N-1):
    if a[i] < a[i+1]:
        pass
    else:
        tmp1 = a[i]
        tmp2 = b[i]
        a[i] = a[i+1]
        b[i] = b[i+1]
        a[i+1] = tmp1
        b[i+1] = tmp2
money=0
for i in range(N):
    money+=a[i]*b[i]
    M-=b[i]
    if M <= 0:
        break
print(money + (a[i] * M))

Submission status: Wrong Answer

Solution code:
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
      break
    i += 1
print(money)

Submission status: Wrong Answer

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: Wrong Answer

Solution code:
N, M = map(int, input().split(" "))
temp = {}
cost = 0
count = 0

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

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


print(cost)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split(" "))
temp = {}
cost = 0
count = 0

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

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
n,s = map(int,stdin.readline().split())
ans = 0
a = []
for i in xrange(n):
  x,y = map(int,stdin.readline().split())
  a.append((y,x))
a.sort()
for x,y in a:
  mi = min(y,s)
  ans += mi * x
  s -= mi
print ans

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split())
def f(x):
    if x%4==3:
        return 0
    elif x%4==0:
        return x
    else:
        base=x-x%3
        ans=base
        for s in range(1,x%3+1):
 #           print(base+s)
            ans^=(base+s)
 #           print(ans)
        return ans
print(f(a-1)^f(b))

Submission status: Wrong Answer

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(key=lambda x:x[0])
i=0
ans=0
while M>l[i][1]:
  M-=l[i][1]
  i+=1
  ans+=l[i][0]*l[i][1]
ans+=l[i][0]*M
print(ans)

Submission status: Wrong Answer

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(key=lambda x:x[0])
i=0
ans=0
while M>l[i][1]:
  M-=l[i][1]
  i+=1
  ans+=l[i][0]+l[i][1]
ans+=l[i][0]*M
print(ans)

Submission status: Wrong Answer

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(key=lambda x:x[1])
i=0
ans=0
while M>l[i][1]:
  M-=l[i][1]
  i+=1
  ans+=l[i][0]+l[i][1]
ans+=l[i][0]*M
print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
mseList = [list(map(int, input().split())) for i in range(0, N)]
mseList = sorted(mseList, key=lambda x:x[0])
total = 0
cnt = 0
for i, k in mseList:
    if cnt < M:
        total += i * k
        cnt += k
        M -= k
    else:
        total += i * M
        break
print(total)

Submission status: Wrong Answer

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

for i, k in mseList:
    if total <= M:
        total += i * k
        M -= k
    else:
        total += i * M
        break
print(total)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
mseList = [list(map(int, input().split())) for i in range(0, N)]
mseList = sorted(mseList)
total = 0
for i, k in mseList:
    if total <= M:
        total += i * k
        M -= k
    else:
        total += i * M
        break
print(total)

Submission status: Wrong Answer

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

a = sorted(a, key=lambda x: x[0])
print(a)
purchase_price = 0


for price, count in a:
    if count < m:
        purchase_price += price * count
        m -= count

    else:
        purchase_price += price * m
        m = 0

print(purchase_price)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
mseList = [list(map(int, input().split())) for i in range(0, N)]
mseList = sorted(mseList)
total = 0
for i, k in mseList:
    if total < M:
        total += i * k
        M -= k
    else:
        total += i * M
        break
print(total)

Submission status: Wrong Answer

Solution code:
store_num, order_num = map(int, input().split())

stores = []
buyed = []
buyed_sum = 0
buy_price = 0

for store_i in range(store_num):
    price, stocks_num = map(int, input().split())
    stores.append({
        'price': price,
        'stocks_num': stocks_num
    })

    if buyed_sum + stores[store_i]['stocks_num'] < order_num:  # この店の全ての本数を買う時
        # 購入済みの list に追加
        buyed.append({
            'price': stores[store_i]['price'],
            'num': stores[store_i]['stocks_num']
        })
        # 総額に追加
        buy_price += stores[store_i]['price'] * stores[store_i]['stocks_num']
        # 購入済みの本数を増やす
        buyed_sum += stores[store_i]['stocks_num']
        # この店の在庫を減らす
        stores[store_i]['stocks_num'] = 0

    elif buyed_sum < order_num:  # この店で一部の本数を買う時(全て買うと多すぎる)
        buy_num = order_num - buyed_sum
        # 購入済みの list に追加
        buyed.append({
            'price': stores[store_i]['price'],
            'num': buy_num
        })
        # 総額に追加
        buy_price += stores[store_i]['price'] * buy_num
        # 購入済みの本数を増やす
        buyed_sum += buy_num
        # この店の在庫を減らす
        stores[store_i]['stocks_num'] -= buy_num

    # まだ在庫が存在するなら
    if stores[store_i]['stocks_num'] > 0:
        for buyed_i in range(len(buyed)):
            if buyed[buyed_i]['price'] > stores[store_i]['price']:  # 今までの店の価格より,今の店の価格が安ければ
                buy_num = min(buyed[buyed_i]['num'], stores[store_i]['stocks_num'])
                # 新しく買った本数を前に買った店から減らす
                buyed[buyed_i]['num'] -= buy_num
                # 買わなくなった価格を総額から減らす
                buy_price -= buyed[buyed_i]['price'] * buy_num
                # 購入済みの list に追加
                buyed.append({
                    'price': stores[store_i]['price'],
                    'num': buy_num
                })
                # 総額に追加
                buy_price += stores[store_i]['price'] * buy_num

print(buy_price)

Submission status: Wrong Answer

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

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

rest = m
result = 0
for p, c in sorted(stock):
  price = int(p)
  count = int(c)
  if rest > count:
    result += count * price
    rest -= count
  else:
    result += rest * price
    break
    
print(result)

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M = list(map(int, input().split()))
A = np.zeros(N)   # A yen
B = np.zeros(N)   # B hon
for i in range(N):
    A[i], B[i] = list(map(int, input().split()))

require = M
price = 0
while(require > 0):
#    print("require = {}, price = {}".format(require, price))
    minidx = np.where(A == A.min())[0][0]
#    print("found idx = " + str(minidx))
    if(require >= B[minidx]):
#        print("buy = {}, price = {}".format(B[minidx], A[minidx]))
        price = price + A[minidx] * B[minidx]
        require = require - B[minidx]
        A = np.delete(A, [minidx])
        B = np.delete(B, [minidx])
    else:
#        print("buy = {}, price = {}".format(require, A[minidx]))
        price = price + A[minidx] * require
        require = 0

print(price)

Submission status: Wrong Answer

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
                X+=m
                print(money)
                break

    B.pop(0)#取り出す

Submission status: Wrong Answer

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+=int(C[l][1])
    if X>M:
        money-=int(C[l][1])*Min
        X-=int(C[l][1])
        for x in range(int(C[l][1])):#何個かえるか
            m+=1
            if M==X+m:#max
                money+=m*Min
                X+=m
                print(money)
                break




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

Submission status: Wrong Answer

Solution code:
def int_raw():
    return int(raw_input())

def ss_raw():
    return raw_input().split()

def ints_raw():
    return map(int,ss_raw())

N,M = ints_raw()
ABs = []
for n_i in xrange(N):
    ABs.append(ints_raw())
ABs.sort()

ans = 0
kosuu = 0
for A,B in ABs:
    n_kosuu = kosuu + B
    if n_kosuu>M:
        ans += (M-kosuu)*A
        break
    else:
        ans = A*B
        kosuu = n_kosuu

print ans

Submission status: Wrong Answer

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+=int(C[l][1])
    if X>M:
        money-=int(C[l][1])*Min
        X-=int(C[l][1])
        for x in range(int(C[l][1])):#何個かえるか
            m+=1
            if M==X+m:#max
                money+=m*Min
                print(money)
                break


    money+=m*Min
    X+=m

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

Submission status: Wrong Answer

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

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

CX=[]
for i in C:
    for j in i:
        try:CX.append(int(j))

        except ValueError:
            pass

CA=[]
CB=[]
i=0

for k in CX:

    if (i+2)%2==0:
        CA.append(CX[i])
    else:
        CB.append(CX[i])
    i+=1



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
    print(Min)
    for x in range(int(C[l][1])):#何個かえるか

        m+=1
        if M==X+m:#max
            money+=m*Min
            print(money)
            break


    money+=m*Min
    X+=m

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

Submission status: Wrong Answer

Solution code:
N,M = [int(x) for x in input().split(' ')]
AB = {}
for i in range(N):
  a,b = [int(x) for x in input().split(' ')]
  AB[a] = b
  
dc = sorted(AB.items())

c = 0
m = M
for s in dc:
  price, stock = s
  if stock >= m:
    c += price * m
    break
  else:
    c += stock * price
    m -= stock
    
print(c)

Submission status: Wrong Answer

Solution code:
N,M = [int(x) for x in input().split(' ')]
AB = {}
for i in range(N):
  a,b = [int(x) for x in input().split(' ')]
  AB[a] = b
  
dc = sorted(AB.items())

c = 0
m = M
for s in dc:
  d = m - s[1]
  if d >= 0:
    m -= s[1]
    c += s[0] * s[1]
    #print(m,c)
    if d == 0:
      break
  else:
    #print(s[1] + d,"xx")
    c += s[0] * (s[1] + d)
    #print(d)
    break
print(c)