Problem:


Score : 300 points

Problem Statement

A programming competition site AtCode provides algorithmic problems.
Each problem is allocated a score based on its difficulty.
Currently, for each integer i between 1 and D (inclusive), there are p_i problems with a score of 100i points.
These p_1 + … + p_D problems are all of the problems available on AtCode.

A user of AtCode has a value called total score.
The total score of a user is the sum of the following two elements:

Base score: the sum of the scores of all problems solved by the user.

Perfect bonuses: when a user solves all problems with a score of 100i points, he/she earns the perfect bonus of c_i points, aside from the base score (1 ≤ i ≤ D).

Takahashi, who is the new user of AtCode, has not solved any problem.
His objective is to have a total score of G or more points.
At least how many problems does he need to solve for this objective?

Constraints

1 ≤ D ≤ 10

1 ≤ p_i ≤ 100

100 ≤ c_i ≤ 10^6

100 ≤ G

All values in input are integers.

c_i and G are all multiples of 100.

It is possible to have a total score of G or more points.

Input

Input is given from Standard Input in the following format:

D G
p_1 c_1
:
p_D c_D

Output

Print the minimum number of problems that needs to be solved in order to have a total score of G or more points. Note that this objective is always achievable (see Constraints).

Sample Input 1

2 700
3 500
5 800

Sample Output 1

3

In this case, there are three problems each with 100 points and five problems each with 200 points. The perfect bonus for solving all the 100-point problems is 500 points, and the perfect bonus for solving all the 200-point problems is 800 points. Takahashi's objective is to have a total score of 700 points or more.

One way to achieve this objective is to solve four 200-point problems and earn a base score of 800 points. However, if we solve three 100-point problems, we can earn the perfect bonus of 500 points in addition to the base score of 300 points, for a total score of 800 points, and we can achieve the objective with fewer problems.

Sample Input 2

2 2000
3 500
5 800

Sample Output 2

7

This case is similar to Sample Input 1, but the Takahashi's objective this time is 2000 points or more. In this case, we inevitably need to solve all five 200-point problems, and by solving two 100-point problems additionally we have the total score of 2000 points.

Sample Input 3

2 400
3 500
5 800

Sample Output 3

2

This case is again similar to Sample Input 1, but the Takahashi's objective this time is 400 points or more. In this case, we only need to solve two 200-point problems to achieve the objective.

Sample Input 4

5 25000
20 1000
40 1000
50 1000
30 1000
1 1000

Sample Output 4

66

There is only one 500-point problem, but the perfect bonus can be earned even in such a case. 



Sample input:
2 700
3 500
5 800


Sample output:
3

Submission status: Runtime Error

Solution code:
d, g = map(int, inputs[0].split())
P = list(map(int, map(lambda x: x.split()[0], inputs[1:])))
C = list(map(int, map(lambda x: x.split()[1], inputs[1:])))

ans = float('inf')
for bit in range(1 << d):
    count, total, rest = 0, 0, set(range(1, d+1))
    for i in range(d):
        if bit & (1 << i):
            total += P[i] * (i + 1) * 100 + C[i]
            count += P[i]
            rest.discard(i + 1)

    if total < g:
        use = max(rest)
        n = ceil((g - total) / (use * 100))
        if P[use-1]-1 < n:
            continue
        count += n
        total += n * use * 100
        
    if total >= g:
        ans = min(ans, count)
print(ans)

Submission status: Runtime Error

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

def f(i,s,count,nokori):
    global ans
    if s<g:
        b=max(nokori)
        n=min(pc[use-1],-(-(g-s)//(b*100)))
        count+=n
        s+=n*b*100
    if s>=g:
        ans=min(ans,count)
    else:
        f(i+1,s,count,nokori)
        f(i+1,s+a[i][0]*100*(i+1)+a[i][0],count+a[i][0],nokori-{i+1})
        
ans=float('inf')
f(0,0,0,set(range(1,d+1)))
print(ans)

Submission status: Runtime Error

Solution code:
from math import ceil
def find_ind(x):
    ans = []
    for n, i in enumerate(x[::-1]):
        if i == "1":
            ans.append(n)
    return ans

def find_0(x):
    for n, i in enumerate(x[::-1]):
        if i == "0":
            ans = n
    return ans

def main():
    d, g = map(int, input().split())
    p = []
    c = []
    for i in range(d):
        p0, c0 = map(int, input().split())
        p.append(p0)
        c.append(c0)

    ans = [] # 回答数リスト
    for i in range(2**d):
        temp = 0
        g_temp = g
        b = bin(i)[2:].rjust(d, "0")
        ind = find_ind(b)
        for i in ind:
            g_temp -= (i+1)*100*p[i] + c[i]
            temp += p[i]
        if g_temp >= 0:
            ind = find_0(b)
            num = ceil(g_temp / ((ind + 1) *100 ) )
            if num < p[ind]:
                ans.append(temp + num)
        else:
            ans.append(temp)
    print(min(ans))

main()

Submission status: Runtime Error

Solution code:
def main():
    d, g = map(int, input().split())
    pc = [list(map(int, input().split())) for _ in range(d)]

    n = len(pc)
    ans = float("inf")

    for i in range(2**n):
        point, cnt = 0, 0
        for j in range(n):
            if (i>>j) & 1:
                point += (j+1)*100*pc[j][0] + pc[j][1]
                cnt += pc[j][0]
        if point >= g:
            ans = min(ans, cnt)
        # print(cnt, point)
        else:
            for j in range(n+1, -1, -1):
                if (i >> j) & 1:
                    continue
                else:
                    for k in range(pc[j][0]):
                        if point >= g:
                            ans = min(ans, cnt)
                            break
                        point += (j+1)*100
                        cnt += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

def ceil(a, b):
    if a%b == 0:
        return a//b
    else:
        return a//b + 1

def main():
    D, G = map(int, input().split())
    pc = [list(map(int, input().split())) for i in range(D)]

    ans = int(1e9)
    for i in range(2**D):
        tmp = 0
        rest = []
        count = 0
        for j in range(D):
            if i&1:# コンプリートする問題
                tmp += (j+1)*100 * pc[j][0] + pc[j][1]
                count += pc[j][0]
            else:
                rest.append(((j+1)*100, pc[j][0]))
            i >>= 1
        rest = sorted(rest, reverse=True)
        rest_point = G - tmp
        if rest_point < 0:
            continue
        tmp = ceil(rest_point, rest[0][0])
        if tmp <= rest[0][1]:
            ans = min(ans, count + tmp)
            # print(rest_point, count, tmp)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
d,g = map(int,input().split())
po = [0]
co = [0]
for i in range(d):
    p,c = map(int,input().split())
    po.append(p)
    co.append(c)

# f(g,i) :　残りG点で、i番目の問題を最大いくつ選べるか
# i番目の問題をn問解いて、
# その得点sがGより小さかったら、f(G-s,i-1)をnに加える。
# ここでiをデクリメントするのは、完全に解く問題より高い得点の問題を
# 中途半端に解くことが最適な問題の選び方ではないため。
# i == 0 の時は float('inf') を返す。（解けない場合）
def f(G,i):
    if i == 0:
        return float("inf")
    n = min(G//(i * 100),po[i])
    s = 100 * i * n 
    if n == po[i]:
        s += c[i]
    if s < G:
        n += f(G-s,i-1)
    return min(n,f(G,i-1))

print(f(g,d))

Submission status: Runtime Error

Solution code:
d,g = map(int,input().split())
po = [0]
co = [0]
for i in range(d):
    p,c = map(int,input().split())
    po.append(p)
    co.append(c)

# f(g,i) :　残りG点で、i番目の問題を最大いくつ選べるか
# i番目の問題をn問解いて、
# その得点sがGより小さかったら、f(G-s,i-1)をnに加える。
# ここでiをデクリメントするのは、完全に解く問題より高い得点の問題を
# 中途半端に解くことが最適な問題の選び方ではないため。
# i == 0 の時は float('inf') を返す。（解けない場合）
def f(G,i):
    if i == 0:
        return float("inf")
    n = min(G//(i * 100),p[i])
    s = 100 * i * n 
    if n == p[i]:
        s += c[i]
    if s < G:
        n += f(G-s,i-1)
    return min(n,f(G,i-1))

print(f(g,d))

Submission status: Runtime Error

Solution code:
dg = input().split(“ “);
d = int(dg[0]);
g = int(dg[1]);
p = [0]*d;
c = [0]*d;
for i in range(d) :
    s = input().split(“ “);
    p[i] = int(s[0]);
    c[i] = int(s[1]);

ans = 0;
for i in range(sum(p)) :
    sump = 0;
    for j in range(len(p)) :
        all = 0;
        for m in range(p[j]) :
            if(i & 2**(sump+m)>>(sump+m)) :
                ans += (j+1)*100;
                all += 1;
        if(all == p[j]) :
            ans += c[j];
        sump += p[i];
print(ans);

Submission status: Runtime Error

Solution code:
ans = 10000
for i in range(2**D):
    s = 0
    cnt = 0
    b = [0] * D
    
    #各問題についてボーナスまで解くか手を付けないかでbit全探索
    for j in range(D):
        if (i >> j) & 1:
            s += 100 * (j + 1) * pc[j][0] + pc[j][1]
            cnt += pc[j][0]
            b[j] = 1

    #足りない点数分を解く
    flag1 = False
    flag2 = True
    if s < G:
        for k in range(D)[::-1]:
            if b[k] == 0:
                for x in range(pc[k][0]):
                    s += 100 * (k + 1)
                    cnt += 1
                    if s >= G:
                        flag1 = True
                        break
                else:
                    flag2 = False
                    break
            if flag1:
                break

    if flag2:
        ans = min(ans, cnt)


print(ans)

Submission status: Runtime Error

Solution code:
def func():
    D, G = map(int, input().split())
    p = [0] * D 
    bonus = [0] * D
    for i in range(D):
        p[i], bonus[i] = map(int, input().split())
    
    ans = 10000
    for i in range(2 ** D):
        chosen = []
        for j in range(D):
            if ((i >> j) & 1) == 1:
                chosen.append(j)
        
        pointSum = 0
        Nsolved = 0
        for idx in chosen:
            pointSum += (idx + 1) * 100 * p[idx] + bonus[idx]
            Nsolved += p[idx]
        
        if pointSum > G:
            continue
        else:
            notChosen = list(filter(lambda x: x not in chosen, list(range(D))))
            highestDimIdx = notChosen[-1]
            if pointSum + (highestDimIdx + 1) * 100 * p[highestDimIdx] >= G:
                rest = G - pointSum
                Nsolved += -(-(rest // ((highestDimIdx + 1) * 100)))
                ans = min(ans, Nsolved)

    print(ans)
        
if __name__ == '__main__':
    func()

Submission status: Runtime Error

Solution code:
import math

d, g = map(int, input().split())
ls = [[100 * (i + 1)] + list(map(int,
                                 input().split())) for i in range(d)][::-1]
l0 = [a * p + c for a, p, c in ls]

res = float('inf')
for index in range(2**d):
    cs = '{:b}'.format(int(cs))
    cs = '0' * (d - len(cs)) + cs
    count = 0
    s = 0
    for i, c in enumerate(cs):
        if c == '1':
            count += ls[i][1]
            s += l0[i]
    if s < g:
        for i, c in enumerate(cs):
            if c == '0' and s + ls[i][0] * ls[i][1] >= g:
                n = math.ceil((g - s) / ls[i][0])
                count += n
                s += ls[i][0] * n
                break
    if s >= g:
        res = min(res, count)
print(res)

Submission status: Runtime Error

Solution code:
import math

d, g = map(int, input().split())
ls = [[100 * (i + 1)] + list(map(int,
                                 input().split())) for i in range(d)][::-1]
l0 = [a * p + c for a, p, c in ls]

res = float('inf')
for index in range(2**d):
    cs = '{:0{d}b}'.format(int(cs))
    count = 0
    s = 0
    for i, c in enumerate(cs):
        if c == '1':
            count += ls[i][1]
            s += l0[i]
    if s < g:
        for i, c in enumerate(cs):
            if c == '0' and s + ls[i][0] * ls[i][1] >= g:
                n = math.ceil((g - s) / ls[i][0])
                count += n
                s += ls[i][0] * n
                break
    if s >= g:
        res = min(res, count)
print(res)

Submission status: Runtime Error

Solution code:
import math

d, g = map(int, input().split())
ls = [[100 * (i + 1)] + list(map(int,
                                 input().split())) for i in range(d)][::-1]
l0 = [a * p + c for a, p, c in ls]

res = float('inf')
for index in range(2**d):
    cs = format(index, 'b')
    cs = '{:0{d}d}'.format(int(cs))
    count = 0
    s = 0
    for i, c in enumerate(cs):
        if c == '1':
            count += ls[i][1]
            s += l0[i]
    if s < g:
        for i, c in enumerate(cs):
            if c == '0' and s + ls[i][0] * ls[i][1] >= g:
                n = math.ceil((g - s) / ls[i][0])
                count += n
                s += ls[i][0] * n
                break
    if s >= g:
        res = min(res, count)
print(res)

Submission status: Runtime Error

Solution code:
import math

d, g = map(int, input().split())
ls = [[100 * (i + 1)] + list(map(int,
                                 input().split())) for i in range(d)][::-1]
l0 = [a * p + c for a, p, c in ls]

res = float('inf')
for index in range(2**d):
    cs = format(index, 'b')
    cs = f'{int(cs):0{d}d}'
    count = 0
    s = 0
    for i, c in enumerate(cs):
        if c == '1':
            count += ls[i][1]
            s += l0[i]
    if s < g:
        for i, c in enumerate(cs):
            if c == '0' and s + ls[i][0] * ls[i][1] >= g:
                n = math.ceil((g - s) / ls[i][0])
                count += n
                s += ls[i][0] * n
                break
    if s >= g:
        res = min(res, count)
print(res)

Submission status: Runtime Error

Solution code:
d, goal = map(int, input().split())
pc = [0] + [list(map(int, input().split())) for _ in range(d)]

def solve(goal, d):
  if d == 0:
    return 10**9
  n = min(goal//(100*d), pc[d][0])
  t = n * d * 100
  if n == pc[d][0]:
    t += pc[d][1]
  if t < goal:
    n += solve(goal-t, d-1)
  return min(n, solve(goal,d-1))

print(solve(g,d))

Submission status: Runtime Error

Solution code:
import copy
MAX_DEPTH  = 1000000000000
give_up = MAX_DEPTH
def solve(rest, score, depth, i):
    global give_up
    if give_up <= depth:
        return 
    score += 100 * (i + 1)
    rest[i] -= 1
    depth += 1
    if rest[i] == 0:
        score += c[i]
    if G <= score:
        return depth
    else:
        all_depth = [MAX_DEPTH]
        min_ans = MAX_DEPTH
        for j in range(0, D):
            if rest[i] != 0:
                ans = solve(copy.deepcopy(rest), score, depth, j)
                if ans and ans <= min_ans:
                    min_ans = ans
                if ans <= give_up:
                    give_up = ans
        return min_ans
 
D,G = [int(x) for x in input().split()]
c = []
rest = []
for _ in range(D):
    _p, _c = [int(x) for x in input().split(" ")]
    rest.append(_p)
    c.append(_c)
results = []
for h in range(D):
  results.append(solve(copy.deepcopy(rest), 0, 0, h))
print(min(results))

Submission status: Runtime Error

Solution code:
d,g=map(int,input().split())
p=[]
c=[]
for i in range(d):
  P,C=map(int,input().split())
  p.append(P)
  c.append(C)
j=0
score=0
cnt=0
while score<g:
  score+=p[d-1-j]*100*(d-j)
  cnt+=p[d-1-j]
  j+=1
print(cnt-((score-g)//p[d-j]))

Submission status: Runtime Error

Solution code:
D, G = list(map(int, input().split(' ')))
left = {}
bonus = {}
for i in range(1, D+1):
    left[i], bonus[i] = list(map(int, input().split(' ')))

big = 9999999

probably_ans = big
def hogehoge(depth, index, pt, left, bonus, probably_ans):
    if depth >= probably_ans:  # 遅いかも
        return big
    if pt >= G:
        return depth
    for i in range(index, D+1):
        if left[i] == 0:
            continue
        left[i] = left[i] - 1
        probably_ans = min(probably_ans, hogehoge(depth+1, i, pt + i * 100 + bonus[i] * (left[i] == 0), left, bonus, probably_ans))
        left[i] = left[i] + 1
    return probably_ans
    
print(hogehoge(0, 1, 0, left, bonus, probably_ans))

Submission status: Runtime Error

Solution code:
D, G = map(int,input().split())
num_q = []
bonus = []
for _ in range(D):
	pp,cc = map(int,input().split())
	num_q.append(pp)
	bonus.append(cc)

cnt = [0] * D
ans = float("inf")

def dfs(cnt, i, score):
	global ans

	if sum(cnt) >= ans:
		return True

	if cnt[i] == num_q[i]:
		score += bonus[i]

	if cnt[D-1] == num_q[D-1]:
		if score >= G:
			ans = min([ans,sum(cnt)])
			return True
		else:
			return True

	if score >= G:
		ans = min([ans,sum(cnt)])
		return True
	
	
	for j in range(i,D):
		if cnt[j] < num_q[j]:
			cnt[j] += 1
			dfs(cnt, j, score+(100*(j+1)))
			cnt[j] -= 1

dfs(cnt,0,0)
print(ans)

Submission status: Runtime Error

Solution code:
D, G = map(int, input().split())
p = [0] * D
c = [0] * D
for i in range(D):
    p[i], c[i] = map(int, input().split())
# 各配点について全問解いた時のポイント
fsp = [p[i]*100*(i+1)+c[i] for i in range(D)]

# print(fsp)

min_pro = 100000000

def dfs(solve):
    global min_pro
    max_rest = -1
    if len(solve) == D:
        sum_point = 0
        sum_pro = 0
        for i in range(D):
            if solve[i] == "1":
                sum_point += fsp[i]
                sum_pro += p[i]
            else:
                max_rest = i
        #print(solve, sum_point, max_rest,math.ceil((G - sum_point) / ((max_rest+1)*100)))
        if sum_point < G:
            if math.ceil((G - sum_point) / ((max_rest+1)*100)) < p[max_rest]:
                sum_pro += math.ceil((G - sum_point) / ((max_rest+1)*100))
            else:
                sum_pro += 100000
        if min_pro > sum_pro:
            min_pro = sum_pro


        #pps[counter] = [sum_point, sum_pro, solve]
        #counter += 1
        return 0

    dfs(solve+"0")
    dfs(solve+"1")
    return 0

dfs("0")
dfs("1")

print(min_pro)
print("\n")

Submission status: Runtime Error

Solution code:
def solve(levelNum, levelProblemNums, extraPoints, target):
	target = int(target / 100)
	dp = [[99999999] * (target+1) for _ in range(levelNum+1)]
	for i in range(levelNum+1):
		dp[i][0] = 0
	#print(dp)
	#print(target)
    return 0
    # for each level
	for l in range(1, levelNum+1):
		#for each point
		#print( l)
		for point in range(1, target+1):
			dp[l][point] = dp[l-1][point]
			for p in range(1, levelProblemNums[l-1]+1):
				curPoint = p*l if p < levelProblemNums[l-1] else p*l + int(extraPoints[l-1]/100)
				subPoint = point - curPoint if point > curPoint else 0
				dp[l][point] = min(dp[l-1][subPoint]+p, dp[l][point])
				if subPoint == 0: break;

	return dp[l][target]	

D, G = map(int, input().split())
P, C = [], []
for i in range(D):
    p, c = map(int, input().split())
    P.append(p)
    C.append(c)

rt = solve(D, P, C, G)
print(rt)

Submission status: Runtime Error

Solution code:
d, g = map(int, input().split())
clist = []
plist = []
for _ in range(d):
    p, c = map(int, input().split())
    clist.append(c)
    plist.append(p)

kumiawase = []
def total(li):
    tmp = [solved*(100*ind) for ind, solved in enumerate(li, start=1)]
    for i in range(d):
        if li[i] == plist[i]:
            tmp.append(clist[i])
    return sum(tmp)

def dfs(D, li):
    if D == d:
        if total(li)>=g:
            global kumiawase
            kumiawase.append(li)
    else:
        for solve_num in range(plist[D] + 1):
            dfs(D+1, li + [solve_num])

dfs(0, [])
ans = kumiawase[0]
for k in n_kumiawase:
    if sum(k) < sum(ans):
        ans = k
print(sum(ans))

Submission status: Runtime Error

Solution code:
d, g = map(int, input().split())
clist = []
plist = []
for _ in range(d):
    p, c = map(int, input().split())
    clist.append(c)
    plist.append(p)

kumiawase = []
def total(li):
    total = 0
    for ind, zip_ in enumerate(zip(li, plist, clist), start=1):
        l, p, c = zip_
        total += l*(100*ind)
        if l == p:
            total +=c
    return total

def dfs(D, li):
    if D == d:
        if total(li)>=g:
            kumiawase.append(li)
    else:
        for solve_num in range(plist[D] + 1):
            dfs(D+1, li + [solve_num])

dfs(0, [])
ans = kumiawase[0]
for k in n_kumiawase:
    if sum(k) < sum(ans):
        ans = k
print(sum(ans))

Submission status: Runtime Error

Solution code:
#%%
import itertools

D, G = map(int, input().split())
p = [0] * D
c = [0] * D
com = [0] * D
for i in range(D):
    p[i], c[i] = map(int, input().split())
    com[i] = [100 * (i+1) * p[i] + c[i], p[i]]

l = list(itertools.product(range(2), repeat=D))
score_list = []
for i in range(len(l)):
    tmp1 = 0
    tmp2 = []
    tmp3 = -1
    tmp5 = 0
    for j in range(D):
        if l[i][j] == 0:
            tmp2.append(j)
            pass
        else:
            tmp1 += com[j][0]
            tmp5 += com[j][1]
    if len(tmp2) != 0:
        tmp3 = tmp2[-1]
    if tmp3 != -1:
        tmp4 = tmp1 + (tmp3+1) * 100 * (p[tmp3]-1)
    else:
        tmp4 = tmp1
    
    score_list.append([tmp1, tmp3, tmp4, tmp5])

#print(score_list)

ans_list = []

for i in range(len(score_list)):
    if score_list[i][2] != -1:
        if score_list[i][0]<= G and score_list[i][2] >= G:
            tmp = (G - score_list[i][0]) // ((score_list[i][1]+1)*100)
            ans = score_list[i][3] + tmp
            ans_list.append(ans)
#            print(score_list[i][3], ans)
    else:
        if score_list[i][0]>= G:
            ans_list.append(score_list[i][3])

#print(ans_list)
print(min(ans_list))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(20000) # 再起呼び出しの最大数をセット

D,G = map(int, input().split())
P = []
C = []
for d in range(D):
    p,c = map(int, input().split())
    P.append(p)
    C.append(c)
#引数piをPのインデックスにして、P[pi」が全てなくなったらpi-1をインデックスにして再帰する
#全問解いたときの特典が高い順に問題をとく。ただし、解いているときのスコアは１問解いたときの最大のものとして解く

#解く順番を決める
Pscore = []
for pi,p in enumerate(P):
    iscore = [100*(pi+1)*p + C[pi], p, pi]
    Pscore.append(iscore)
Porder = sorted(Pscore, key=lambda k:k[1])#Pの中身でソート、問題数の少ない順にソート
#リストの最初から再帰的に完全に解くことを試す
#各段階で、残っている配列うちで完全に解けるものがあれば、それを順番に解いて、なければ最も点数が高いものを不完全に解く
#引数に与えたcount数で解ける問題を全部探索して、その中での最大スコアを戻す
import copy
def fullSearch(count, Porder):
    maxp = [0,0,0]#最も点数が高い問題
    for p in Porder:
        if maxp[2] <= p[2]:
            maxp = p
    mscore = 0
    if count < Porder[0][1]:#　残りcountで完全に解ける問題が存在しないとき
        score = 100*(maxp[2]+1)*count
        return score
    else:
        for p in Porder:
            if p[1] <= count:
                newPorder = copy.deepcopy(Porder)
                newPorder.remove(p)
                score = p[0] + fullSearch(count-p[1], newPorder)
                if mscore < score:
                    mscore = score
            else:
                break
        if count <= maxp[1]:
            score = 100*(maxp[2]+1)*count
            if mscore < score:
                mscore = score
        return mscore
count = 0
while True:
    count += 1
    if fullSearch(count, Porder) >= G:
        break
print(count)

Submission status: Runtime Error

Solution code:
D,G = map(int, input().split())
P = []
C = []
for d in range(D):
    p,c = map(int, input().split())
    P.append(p)
    C.append(c)
#引数piをPのインデックスにして、P[pi」が全てなくなったらpi-1をインデックスにして再帰する
#全問解いたときの特典が高い順に問題をとく。ただし、解いているときのスコアは１問解いたときの最大のものとして解く

#解く順番を決める
Pscore = []
for pi,p in enumerate(P):
    iscore = [100*(pi+1)*p + C[pi], p, pi]
    Pscore.append(iscore)
Porder = sorted(Pscore, key=lambda k:k[1])#Pの中身でソート、問題数の少ない順にソート
#リストの最初から再帰的に完全に解くことを試す
#各段階で、残っている配列うちで完全に解けるものがあれば、それを順番に解いて、なければ最も点数が高いものを不完全に解く
#引数に与えたcount数で解ける問題を全部探索して、その中での最大スコアを戻す
import copy
def fullSearch(count, Porder):
    maxp = 0#最も点数が高い問題のインデックス
    for p in Porder:
        if maxp <= p[2]:
            maxp = p[2]
    mscore = 0
    if count < Porder[0][1]:#　残りcountで完全に解ける問題が存在しないとき
        score = 100*(maxp+1)*count
        return score
    else:
        for p in Porder:
            if p[1] <= count:
                newPorder = copy.deepcopy(Porder)
                newPorder.remove(p)
                score = p[0] + fullSearch(count-p[1], newPorder)
                if mscore < score:
                    mscore = score
            elif p[2] == maxp:
                if p[1] > count:
                    score = 100*(maxp+1)*count
                    if mscore < score:
                        mscore = score
        return mscore
count = 0
while True:
    count += 1
    if fullSearch(count, Porder) >= G:
        break
print(count)

Submission status: Runtime Error

Solution code:
from math import ceil

D,G = map(int,input().split())

pc_list = [[i]+list(map(int,input().split())) for i in range(D)]


def func(g,cnt,l):
    if len(l) == D:
        if g <= 0:
            return cnt
        idx = rindex_zero(l)
        i,p,c = pc_list[idx]
        if g < 100*(i+1)*(p-1):
            cnt += ceil(g/(100*(i+1)))
            return cnt
        return 10**9
    length = len(l)
    i,p,c = pc_list[length]
#     print(i,p,c,l)
    a = func(g-(100*(i+1)*p+c), cnt+p,l+[1])
    b = func(g, cnt,l +[0])
    return min(a,b)
        
print(func(G,0,[]))

Submission status: Runtime Error

Solution code:
n, l, t = list(map(int, input().split()))
ants = []
for i in range(n):
    ants.append(list(map(int, input().split())))
normal_ant = [i for i, direction in ants if direction==1]
counter_ant = [i for i, direction in ants if direction==2]
cnt = (t // l) * len(normal_ant) + sum([1 for i in normal_ant if i + t%l >= l])
counter_cnt = (t // l) * len(counter_ant) + sum([1 for i in counter_ant if i - t%l < 0])
final_pos = sorted([(i-t)%l for i in counter_ant] + [(i+t)%l for i in normal_ant])
print(*final_pos[(cnt-counter_cnt)%n:] + final_pos[:(cnt-counter_cnt)%n], sep='\n')

Submission status: Runtime Error

Solution code:
score_max, total = list(map(int, input().split()))
total //= 100
per_score_num = []
bonus = []
for i in range(score_max):
    inp = list(map(int, input().split()))
    per_score_num.append(inp[0])
    bonus.append(int(inp[1] / 100))
    

require = 0
min_cnt = np.inf


for bits in range(1 << score_max):
    solve_cnt = 0
    score = 0
    for i in range(score_max):
        if (1<<i)&bits:
            score += per_score_num[i] * (i+1)
            score += bonus[i]
            solve_cnt += per_score_num[i]
    if total > score:
        for j in range(score_max-1, -1, -1):
            if not (1<<j) & bits:
                require = math.ceil((total - score) // (j+1))
                if require < per_score_num[j]:
                    solve_cnt += require
                else:
                    solve_cnt = np.inf
                break
    min_cnt = min(min_cnt, solve_cnt)
print(min_cnt)

Submission status: Runtime Error

Solution code:
import itertools
import math


D, G = map(int, input().split())

P     = [None] * D
C     = [None] * D
count = [None] * D
score = [None] * D

for i in range(D):
    p, c          = map(int, input().split())
    P[i]          = p
    C[i]          = c
    count[i]      = list(range(p+1))
    score[i]      = [100 * (i+1) * j for j in range(p+1)]
    score[i][-1] += c

answer = math.inf

for is_complete in itertools.product([True, False], repeat=D):
    score_tmp  = 0
    count_tmp  = 0
    score_tmp += sum([score[i][-1] for i in range(D) if is_complete[i]])
    count_tmp += sum([count[i][-1] for i in range(D) if is_complete[i]])
    while score_tmp < G:
        for i in list(range(D))[::-1]:
            if is_complete[i] == False:
                if (G - score_tmp) % (100 * (i+1)) == 0:
                    count_add  = min((G - score_tmp) // (100 * (i+1)),     P[i] - 1)
                else:
                    count_add  = min((G - score_tmp) // (100 * (i+1)) + 1, P[i] - 1)
                score_add      = 100 * (i+1) * count_add
                count_tmp     += count_add
                score_tmp     += score_add
            if score_tmp >= G:
                break
    if score_tmp >= G:
        answer = min(answer, count_tmp)

print(answer)

Submission status: Runtime Error

Solution code:
def cal_g(g, point, p):
    for i in range(p):
        g -= point
        if g <= 0:
            return i+1
    return p
        
    
d, g = map(int, input().split())
li = [list(map(int, input().split())) for _ in range(d)]
li = [[li[i][0], li[i][1], li[i][0]*(i+1)*100+li[i][1], (i+1)*100 + (li[i][1]/ li[i][0]), (i+1)*100] for i in range(len(li))]

li.sort(reverse = True, key = lambda x : (x[3], -x[0]))
ans = 0
for i in li[:]:   
    if i[2] < g:
        g -= i[2]
        li.pop(0)
        ans += i[0]
    else:
        break

ans_li = []
for i in li[:]:
    if i[2] > g:
        ans_li.append(cal_g(g, i[4], i[0]))

print(ans + min(ans_li))

Submission status: Runtime Error

Solution code:
d,g=map(int,input().split())
p=[]
c=[]
count=0
for i in range(d):
    pi,ci=map(int,input().split())
    p.append(pi)
    c.append(ci)
e=[]
for i in range(d):
    x=p[i]*(i+1)*100+c[i]
    y=x/p[i]
    e.append([y,x,i,p[i]])
e.sort(reverse=True)
for i in range(d):
    if g>=e[0][1]:
        count+=p[e[0][2]]
        g=g-e[0][1]
        aa=e.pop(0)
        #print(aa)
    else:
        break
e.sort(key=lambda x:x[3],reverse=True)
print(count+g//((e[0][2]+1)*100))

Submission status: Runtime Error

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

import numpy as np
import copy

dt=[0]*n
cp=[0]*n
ck=[0]*n

for i in range(n):
	dt[i]=100*(i+1)+q[i][1]//q[i][0]
	cp[i]=100*(i+1)*q[i][0]+q[i][1]

score=sum(cp)
cnt=np.sum(q, axis=0)[0]

for i in range(n):
	id=np.argmin(dt)
	score-=cp[id]
	cnt-=q[id][0]
	dt[id]=999999999
	ck[id]=i+1
	if score<=s:
		break

cnt1=999
for i in range(n):
	if dt[i]==999999999:
		if cp[i]+score>=s:
			cnt1=min(cnt1,q[i][0])

res1=cnt+cnt1

for i in range(n):
	if ck[n-1-i]>0:
  		id2=n-1-i
  		break

for i in range(q[id2][0]):
	score+=(id2+1)*100
	if score>=s:
		res2=cnt+i+1
		break

print(min(res1,res2))

Submission status: Runtime Error

Solution code:
d, g = map(int, input().split())
g = g // 100
tmp = 0
cands = []
for i in range(1, d + 1):
  p, c = map(int, input().split())
  cand = [i for _ in range(p)]
  cand[-1] += c
  tmp += sum(cands)
  cands.append(cand)
  
while True:
  if tmp <= g:
    print(sum([len(cand) for cand in cands]))
    break
  lasts = [cand[-1] for cand in cands]
  index = lasts.index(min(lasts))
  tmp -= lasts[index]
  cands[index] = cands[index][:-1]

Submission status: Runtime Error

Solution code:
import itertools
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

D, G = list(map(int, sys.stdin.readline().split()))
P, C = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(D)]))

P = np.array(P, dtype=int)
C = np.array(C, dtype=int)
A = np.arange(1, D + 1, dtype=int) * 100  # 1問のスコア
comp_scores = P * A + C

# ans = P.sum()
# for i in range(D):
#     # i: 途中まで解く
#     # comp: True ならその問題は全部解く
#     for comp in itertools.product([True, False], repeat=D):
#         comp = np.array(comp)
#         comp[i] = False
#         cnt = P[comp].sum()
#         score = comp_scores[comp].sum()
#         add_cnt = max(0, min(P[i] - 1, math.ceil((G - score) / A[i])))
#         add_score = A[i] * add_cnt
#         if score + add_score >= G:
#             ans = min(ans, cnt + add_cnt)
# print(ans)

ans = P.sum()
for i in range(D):
    # i: 途中まで解く
    # True なら全部解く、False なら 1 問も説かない
    patterns = np.array(list(itertools.product([True, False], repeat=D)))
    patterns[:, i] = False
    cnt = np.dot(patterns, P)
    score = np.dot(patterns, comp_scores)
    add_cnt = np.maximum(0, np.minimum(P[i] - 1, np.ceil((G - score) / A[i])))
    add_score = A[i] * add_cnt
    ans = min(ans, ((cnt + add_cnt)[score + add_score >= G]).min())
print(int(ans))