input
stringlengths 20
127k
| target
stringlengths 20
119k
| problem_id
stringlengths 6
6
|
---|---|---|
dp = [[0 for n in range(1001)] for m in range(11)]
length, goal = list(map(int, input().split(" ")))
problems = []
for l in range(length):
a, b = list(map(int, input().split(" ")))
problems.append([a, b])
for i in range(length):
max_problems = problems[i][0]
for k in range(1000):
if dp[i][k]:
for l in range(max_problems):
dp[i + 1][k + 1 + l] = max(dp[i + 1][k + 1 + l], dp[i][k] + (i + 1) * 100 * (l + 1) + (problems[i][1] * int(l + 1 == max_problems)) )
dp[i + 1][k] = max(dp[i + 1][k], dp[i][k])
for l in range(max_problems):
dp[i + 1][1 + l] = max(dp[i + 1][1 + l], (i + 1) * 100 * (l + 1) + (problems[i][1] * int(l + 1 == max_problems)) )
# print(dp[i + 1][1])
answer = float("inf")
for i in range(11):
for j in range(1001):
if dp[i][j] >= goal:
answer = min(answer, j)
print(answer)
|
import math
length, goal = list(map(int, input().split(" ")))
nums = []
sumall = []
for i in range(length):
a, b = list(map(int, input().split(" ")))
nums.append(a)
sumall.append(a * (i + 1) * 100 + b)
answer = float("inf")
for bit in range(2 ** length):
temp = []
for i in range(length - 1, -1, -1):
if bit & (1 << i):
temp.append(i)
temp_length = len(temp)
for tempbit in range(2 ** temp_length):
temp_sum = 0
choosed = 0
for i in range(temp_length):
if tempbit & (1 << i):
temp_sum += sumall[temp[i]]
choosed += nums[temp[i]]
if temp_sum >= goal:
answer = min(answer, choosed)
break
else:
if temp_sum + (nums[temp[i]] - 1) * (temp[i] + 1) * 100 >= goal:
answer = min(answer, choosed + int(math.ceil((goal - temp_sum) / (100 * (temp[i] + 1)))) )
break
temp_sum += (nums[temp[i]] - 1) * (temp[i] + 1) * 100
choosed += nums[temp[i]] - 1
# print(bin(bit), bin(tempbit), temp_sum, choosed, answer)
# print(answer, bin(bit))
print(answer)
|
p03290
|
d, g = list(map(int, input().split()))
pc = [list(map(int, input().split())) for i in range(d)]
def dfs(s=[], score=0):
ans = float('inf')
if len(s)==d:
if score >= g:
return sum(s)
else:
return float('inf')
else:
p, c = pc[len(s)]
for i in range(p+1):
a = 100*(len(s)+1)*i
if i==p:
a+=c
ans = min(ans, dfs(s+[i], score+a))
return ans
print((dfs([])))
|
from itertools import product
from math import ceil
d, g = list(map(int, input().split()))
pc = [list(map(int, input().split())) for i in range(d)]
ans = 10**9
for bit in product([0, 1], repeat=d):
score = 0
probs = 0
for i, b in enumerate(bit):
p, c = pc[i]
if b==1:
probs+=p
score+=100*(i+1)*p
score+=c
if score >= g:
ans = min(ans, probs)
else:
# greedyに足す
for i, b in list(enumerate(bit))[::-1]:
p, c = pc[i]
if b==1:
continue
if score+100*(i+1)*p >= g:
a = ceil((g-score)/(100*(i+1)))
probs += a
score += (100*(i+1))*a
if a == p: score += c
break
else:
probs += p
score += (100*(i+1))*p+c
if score >= g: break
if score >= g:
ans = min(ans, probs)
print(ans)
|
p03290
|
import math
from itertools import permutations
D, G = list(map(int, input().split(' ')))
questions = [tuple(map(int, input().split(' '))) for _ in range(D)]
min_answer = 1000
for question_ids in permutations(list(range(D))):
score = G
answer = 0
for question_id in question_ids:
n, bonus = questions[question_id]
point = 100 * (question_id + 1)
n_ans = min(n, math.ceil(score / point))
answer += n_ans
score -= n_ans * point
if n_ans == n:
score -= bonus
if score <= 0:
min_answer = min(min_answer, answer)
break
print(min_answer)
|
from itertools import product
D, G = list(map(int, input().split(' ')))
questions = [tuple(map(int, input().split(' '))) for _ in range(D)]
questions = [(100 * index, n, bonus) for index, (n, bonus) in enumerate(questions, start=1)]
min_answer = 1000
for bits in product((True, False), repeat=D):
not_complete = []
score = G
answered = 0
for index, bit in enumerate(bits):
if not bit:
not_complete.append(index)
continue
point, n, bonus = questions[index]
score -= point * n + bonus
answered += n
if not_complete:
index = max(not_complete)
point, n, _ = questions[index]
while score > 0 and n > 1:
score -= point
n -= 1
answered += 1
if score <= 0:
min_answer = min(min_answer, answered)
print(min_answer)
|
p03290
|
import sys
input = sys.stdin.readline
d, g = [int(x) for x in input().split()]
pc = [[int(x) for x in input().split()] for _ in range(d)]
ans = float("inf")
for i in range(2 ** d):
i_bin = bin(i)[2:].zfill(d)
s = set() # コンプリートボーナスをもらう
for j in range(len(i_bin)):
if i_bin[j] == "1":
s.add(j)
cnt = 0
total = 0
for k in s:
cnt += pc[k][0]
total += (k + 1)*pc[k][0]*100 + pc[k][1]
if total >= g:
ans = min(ans, cnt)
continue
for l in range(d - 1, -1, -1):
flag = 0
if l in s:
continue
for m in range(1, pc[l][0]):
total += (l + 1) * 100
cnt += 1
if total >= g:
flag = 1
break
if flag:
break
if total >= g:
ans = min(ans, cnt)
print(ans)
|
import sys
input = sys.stdin.readline
d, g = [int(x) for x in input().split()]
pc = [[int(x) for x in input().split()] for _ in range(d)]
ans = float("inf")
for i in range(2 ** d):
s = set() # コンプリートボーナスをもらう
for j in range(d):
if (i >> j) & 1:
s.add(j)
cnt = 0
total = 0
for k in s:
cnt += pc[k][0]
total += (k + 1)*pc[k][0]*100 + pc[k][1]
if total >= g:
ans = min(ans, cnt)
continue
for l in range(d - 1, -1, -1):
flag = 0
if l in s:
continue
for m in range(1, pc[l][0]):
total += (l + 1) * 100
cnt += 1
if total >= g:
flag = 1
break
if flag:
break
if total >= g:
ans = min(ans, cnt)
print(ans)
|
p03290
|
D,G = list(map(int,input().split()))
P = []
num_p = 0
for i in range(1,D+1):
p,c = list(map(int,input().split()))
num_p += p
for j in range(1,p+1):
P += [(j,i*100*j+c*(j==p))]
dp = [0]*(num_p+1)
for k,pt in P:
if k==1:
t_dp = dp[:]
for cur in range(1,num_p+1):
if cur>=k:
dp[cur] = max(dp[cur], t_dp[cur-k]+pt)
for i in range(num_p+1):
if dp[i]>=G:
print(i)
break
|
d,g = list(map(int,input().split()))
pc = [list(map(int,input().split()))for _ in[0]*d]
ans = []
for mask in range(1 << d):
s = 0
num = 0
rest_max = -1
for i in range(d):
p,c = pc[i]
if mask >> i & 1:
s += p * 100 * (i + 1) + c
num += p
else:
rest_max = i
if s < g:
s1 = 100 * (rest_max + 1)
need = (g - s + s1 - 1) // s1
if need >= pc[rest_max][0]:
continue
num += need
ans.append(num)
print((min(ans)))
|
p03290
|
D, G = [int(i) for i in input().split()]
PC = [(int(i), int(j)) for (i, j) in [input().split() for _ in range(D)]]
# 十分大きい数を用意する
ans = float("inf")
# それぞれのランクの問題を「完全に解く」 or not -> 2^D通り
for bit in range(1 << D):
score = 0
solve = 0
rest = set(range(1, D + 1))
for i in range(D):
# (i+1)番目の問題を完全に解いた場合
if (bit>>i) & 1:
# スコア = 基本スコア + コンプリートボーナス
score += PC[i][0] * (i + 1) * 100 + PC[i][1]
solve += PC[i][0]
# 今回解いたランクの問題を削除
rest.discard(i + 1)
# 目標点に満たない場合、restの大きいものから順に解く
if score < G:
target = max(rest)
n = min(PC[target - 1][0], -((score-G) // (target*100)))
score += n * target * 100
solve += n
if score >= G:
ans = min(ans, solve)
print(ans)
|
import itertools
d, g = [int(i) for i in input().split()]
pc = [[int(i) for i in input().split()] for _ in range(d)]
ans = float("inf")
for bit in itertools.product((0, 1), repeat=d):
score = 0
solve = 0
rest = set(range(d))
for i in range(d):
if bit[i] == 1:
score += pc[i][0] * (i+1) * 100 + pc[i][1]
solve += pc[i][0]
rest.discard(i)
if score < g:
problem = max(rest)
needs = -((-(g - score)) // ((problem+1)*100))
n = min(pc[problem][0] - 1, needs)
score += n * (problem+1) * 100
solve += n
if score >= g:
ans = min(ans, solve)
print(ans)
|
p03290
|
D, G = list(map(int, input().split()))
p, c = [], []
for i in range(D):
a, b = list(map(int, input().split()))
p.append(a)
c.append(b)
from itertools import product
res = 1 << 29
for v in product([0, 1], repeat=D):
score, num = 0, 0
for i in range(D):
if v[i] == 1:
score += c[i] + p[i] * 100 * (i + 1)
num += p[i]
if score >= G:
res = min(res, num)
else:
for j in range(D - 1, -1, -1):
if v[j] == 1:
continue
for k in range(p[j]):
if score >= G:
break
score += 100 * (j + 1)
num += 1
res = min(res, num)
print(res)
|
D, G = list(map(int, input().split()))
p, c = [], []
for i in range(D):
a, b = list(map(int, input().split()))
p.append(a)
c.append(b)
res = 1 << 29
for bit in range(1 << D):
score, num = 0, 0
for i in range(D):
if bit >> i & 1: # bit & (i << i)
score += c[i] + p[i] * 100 * (i + 1)
num += p[i]
if score >= G:
res = min(res, num)
else:
for j in range(D - 1, -1, -1):
if bit >> j & 1: # bit & (i << i)
continue
for k in range(p[j]):
if score >= G:
break
score += 100 * (j + 1)
num += 1
res = min(res, num)
print(res)
|
p03290
|
D,G = list(map(int, input().split()))
#prob_num = [3,5]
#comp = [500,800]
prob_num = []
comp = []
for i in range(D):
p,c = list(map(int, input().split()))
prob_num.append(p)
comp.append(c)
comp_point = []
for i in range(D):
comp_point.append((100*(i+1)*prob_num[i]+comp[i]))
ans = 1000000
for b in range(1<<D):
hasComp = []
for j in range(D):
if b & (1<<j):
hasComp.append(True)
else:
hasComp.append(False)
# compしてるものを決め打ち
point = 0
prb = 0
for i in range(D):
if hasComp[i]:
point += comp_point[i]
prb += prob_num[i]
res = G-point
while res>0:
flag = 0
for i in range(D-1,-1,-1):
if not hasComp[i]:
if res <= (100*(i+1)*(prob_num[i]-1)):
req_prob = (res//(100*(i+1))) + bool(res%(100*(i+1)))
prb += req_prob
res = 0
break
else:
prb += (prob_num[i]-1)
res -= (100*(i+1))*(prob_num[i]-1)
if i==0:
flag = 1
break
if flag:
break
if res<=0:
ans = min(ans,prb)
print(ans)
|
D,G = list(map(int, input().split()))
prob_num = []
bonus = []
comp_pt = []
for i in range(D):
p,b = list(map(int, input().split()))
prob_num.append(p)
bonus.append(b)
comp_pt.append(100*(i+1)*p+b)
def dfs(hascomp:str, target:int, prob:int, depth:int) -> int:
if target <= 0:
#print(hascomp, depth, prob)
return prob
elif depth == D:
for i in range(D-1,-1,-1):
if hascomp[i] == "n":
if target <= 100*(i+1)*(prob_num[i]-1):
prob += (target//(100*(i+1)))+bool(target%(100*(i+1)))
#print(hascomp, depth, prob)
return prob
else:
prob += (prob_num[i]-1)
target -= 100*(i+1)*(prob_num[i]-1)
if target > 0:
#print(hascomp, depth, prob)
return 10**5
else:
new_tar = target-comp_pt[depth]
new_prob = prob + prob_num[depth]
return min(dfs(hascomp+"y",new_tar, new_prob, depth+1),
dfs(hascomp+"n",target, prob, depth+1))
ans = dfs("",G,0,0)
print(ans)
|
p03290
|
n,g = list(map(int,input().split()))
lis = []
mon = []
for i in range(n):
a,b = list(map(int,input().split()))
lis.append([a,b])
score = {(0,0)}
for i in range(n):
gone = set()
for nu,cou in score:
for j in range(lis[i][0]+1):
if j != lis[i][0]:
gone.add((nu+(i+1) * 100 * j,cou + j))
else:
gone.add((nu+(i+1) * 100 * j + lis[i][1],cou + j))
score = gone
ans = 10 ** 12
for nu,num in score:
if nu >= g:
ans = min(ans,num)
print(ans)
|
import math
n,g = list(map(int,input().split()))
lis = []
sum = []
for i in range(n):
a,b = list(map(int,input().split()))
lis.append([a,b])
sum.append((i+1)*100*a+b)
def ans(x,y):
if y <= 0:return 10 ** 12
nu = min(math.ceil(x/(100 * y)),lis[y-1][0])
num = 100 * y * nu
if nu == lis[y-1][0]:num += lis[y-1][1]
if num >= x:cou = nu
else:cou = nu +ans(x-num,y-1)
return min(cou,ans(x,y-1))
print((ans(g,n)))
|
p03290
|
d,g = list(map(int,input().split()))
p = [] # 問題数の格納
c = [] # ボーナス点の格納
ans = [] # 候補解の格納
ss = 0
cnt = 0
for _ in range(d): #問題数、ボーナス点の入力
pp,cc = list(map(int,input().split()))
p.append(pp)
c.append(cc)
for x in range(2**d): #bit全探索
ss = 0 # 得点
cnt = 0 # 問題数
for i in range(d): #bit探索
if (x >> i) & 1:
ss += (i+1)*100*p[i] + c[i]
cnt += p[i]
if ss >= g: # 既に得点がg以上の時、ansに格納
ans.append(cnt)
else:
for l in range(d)[::-1]:
if ((x>>l)&1):
continue
for _ in range(1,p[l]):
ss += (l+1) * 100
cnt += 1
if ss >= g:
ans.append(cnt)
break
print((min(ans)))
|
d,g = list(map(int,input().split()))
P, C = [], []
probs = set([i for i in range(d)])
for _ in range(d):
p,c = list(map(int,input().split()))
P.append(p)
C.append(c)
res = float('inf')
for i in range(2**d):
tmp = []
score = 0
cnt = 0
for j in range(d):
if ((i>>j)&1):
tmp.append(j)
for k in tmp:
score += (k+1)*100*P[k] + C[k]
cnt += P[k]
if score >= g:
res = min(res, cnt)
else:
x = list(probs - set(tmp))
x.sort(reverse=True)
for x_ in x:
for _ in range(P[x_]):
score += (x_+1)*100
cnt += 1
if score >= g:
res = min(res, cnt)
break
print(res)
|
p03290
|
import re
d,g = list(map(int,input().split() ))
l = [list(map(int,input().split() ))+[100*(x+1)] for x in range(d) ]
mondai_num = []
for k in range(2**d):
#先に全完するカテゴリ(何百点問題を全完するか)を決め、回す
bin_str = format(k, "0{}b".format(d) )#二進数の文字列を取得
#これが全完する問題のリスト
zenkan_list = [ x.start() for x in re.finditer("1",bin_str) ]
#0~9のリストと和の初期化
d_list = [i for i in range(d)]
wa = 0
cnt = 0
#全完した点数のみ先に足す
for i in zenkan_list:
wa = wa+(l[i][0])*((i+1)*100)
wa = wa + l[i][1]
cnt = cnt + l[i][0]
#全完したやつだけで目標を超えたらそこでストップ
if wa>=g:
mondai_num.append( cnt )
#全完したやつだけでたらなかったら素点が大きいやつを全完一歩手前まで足す
else:
#全完したカテゴリを除外
for i in zenkan_list:
d_list.remove(i)
#残ったカテゴリの中で最大の点数のカテゴリを探す
max_set = l[max(d_list)]
for i in range( max_set[0] ):
wa = wa + max_set[2]
if wa >= g:
mondai_num.append(cnt + i+1 )
break
print((min(mondai_num)))
|
import math
D,G = list(map(int,input().split()))
p = []
c = []
for i in range(D):
P,C = list(map(int,input().split()))
p.append(P)
c.append(C)
res = float("inf")
for i in range(2**D):
bs = format(i,"0{}b".format(D))
ans = 0
cnt = 0
#コンプするやつをたす
for j in range(D):
if bs[j] == "1":
ans += (j+1)*100*p[j] + c[j]
cnt += p[j]
if ans >= G:
res = min(cnt,res)
continue
#コンプしないやつを寸止めでたす
for j in range(D-1,-1,-1):
if bs[j] == "0":
ans += (j+1)*100*(p[j]-1)
cnt += (p[j]-1)
if ans >= G:
cnt -= (ans-G)//((j+1)*100)
res = min(res,cnt)
break
print(res)
|
p03290
|
d,g = list(map(int, input().split()))
p = []
c = []
for i in range(d):
a,b = list(map(int, input().split()))
p.append(a)
c.append(b)
dp = [0 for i in range(sum(p) + 2)]
for i in range(1,d+1):
count_max = p[i-1]
bonus = c[i-1]
for j in range(sum(p)+1,0,-1):
for k in range(1,count_max+1):
if k < count_max:
cc = 100 * i * k
if k == count_max:
cc = 100 * i * k + bonus
if j - k >= 0:
dp[j] = max(dp[j],dp[j-k] + cc)
for i,j in enumerate(dp):
if g <= j:
print(i)
break
|
d,g = list(map(int, input().split()))
P = []
C = []
PC = []
for i in range(d):
p,c = list(map(int, input().split()))
P.append(p)
C.append(c)
PC.append((p,c))
P_sum = sum(P)
dp = [0 for i in range(P_sum + 1)]
for i,j in enumerate(PC):
for k in range(P_sum, -1, -1):
for l in range(1,j[0]+1):
if l + k <= P_sum:
if l == j[0]:
cc = 100 * (i + 1)* l + j[1]
else:
cc = 100 * (i + 1) * l
dp[l + k] = max(dp[l + k ], dp[k] + cc)
for i,j in enumerate(dp):
if j >= g:
print(i)
break
|
p03290
|
from operator import itemgetter
D, G = list(map(int, input().split()))
PC = [list(map(int, input().split())) for _ in range(D)]
def score(d, n, s, ans):
if s >= G:
ans = min(ans, n)
return ans
if d == D:
if s >= G:
ans = min(ans, n)
return ans
p, c = PC[d]
for k in range(p+1):
if k == p:
ans = score(d+1, n+k, 100*(d+1)*k + c + s, ans)
else:
ans = score(d+1, n+k, 100*(d+1)*k + s, ans)
return ans
print((score(0, 0, 0, 1000)))
|
from operator import itemgetter
D, G = list(map(int, input().split()))
PC = [list(map(int, input().split())) for _ in range(D)]
def com(d, s, ans):
if d == D:
ans.append(s)
return ans
a = s[:]
a.append(1)
ans = com(d+1, a, ans)
b = s[:]
b.append(0)
ans = com(d+1, b, ans)
return ans
L = com(0, [], [])
ans = 10000
for l in L:
point = 0
probs = 0
uncom = []
for i, com in enumerate(l):
if com == 0:
uncom.append(i)
else:
p, c = PC[i]
point += (i+1)*100*p + c
probs += p
#print(probs, l)
if point >= G:
ans = min(ans, probs)
continue
uncom.sort(reverse=True)
re = G - point
for un in uncom:
p, c = PC[un]
#print(re, probs, p)
if (un+1)*100*(p-1) >= re:
rem = 1 if re % ((un+1)*100) > 0 else 0
probs += re // ((un+1)*100) + rem
re = 0
break
re -= (un+1)*100*(p-1)
probs += p-1
#print(probs)
if re > 0:
continue
ans = min(ans, probs)
print(ans)
|
p03290
|
d, g = [int(i) for i in input().split()]
score = 0
p = []
c = []
for i in range(d):
p_tmp, c_tmp = [int(i) for i in input().split()]
p.append(p_tmp)
c.append(c_tmp)
num = []
for i in range(2**d):
num_tmp = 0
score = 0
not_comp = []
for j in range(d):
if i >> j & 1:
score += p[j] * 100 * (j+1) + c[j]
num_tmp += p[j]
else:
not_comp.append(j)
for j in not_comp[::-1]:
for k in range(p[j]-1):
if score < g:
score += 100 * (j+1)
num_tmp += 1
else:
break
else:
continue
break
if score >= g:
num.append(num_tmp)
ans = min(num)
print(ans)
|
d, g = [int(i) for i in input().split()]
score = 0
p = []
c = []
for i in range(d):
p_tmp, c_tmp = [int(i) for i in input().split()]
p.append(p_tmp)
c.append(c_tmp)
num = []
for i in range(2**d):
num_tmp = 0
score = 0
not_comp = []
for j in range(d):
if i >> j & 1:
score += p[j] * 100 * (j+1) + c[j]
num_tmp += p[j]
else:
not_comp.append(j)
for j in not_comp[::-1]:
if score < g:
num_j = min(p[j]-1, (g-score-1)//(100*(j+1))+1)
score += num_j * 100*(j+1)
num_tmp += num_j
if score >= g:
num.append(num_tmp)
ans = min(num)
print(ans)
|
p03290
|
D, G = list(map(int, input().split()))
P = []
for i in range(D):
p, c = list(map(int, input().split()))
P.append((p, c))
ans = float("inf")
for i in range(2 ** D):
score = 0
index = []
attempt = 0
for j in range(D):
if ((i >> j) & 1):
p, c = list(map(int, P[j]))
score += (c + p * (100 * (j+1) ))
attempt += p
index.append(j)
if score >= G: # コンプリートボーナスのみでスコアを超えている場合
ans = min(ans, attempt)
continue
for i in range(D)[::-1]: # 個別に計算して足していく
if score >= G: # スコアを達成した場合は終了
break
if i in index: # コンプリートしてたりするやつはスキップ
continue
p, c = list(map(int, P[i]))
for j in range(p):
score += 100 * (i+1)
attempt += 1
if score >= G: # スコアを達成した場合は終了
ans = min(ans, attempt)
break
else:
index.append(i)
print(ans)
|
D, G = list(map(int, input().split()))
from itertools import chain
S = []
for i in range(D):
p, c = list(map(int, input().split()))
S.append((p, c))
L = []
for i in range(2**D):
T = []
for j in range(D):
if (i>>j) & 1:
T.append(j)
L.append(T)
X = []
for l in L:
score, count = 0, 0
for m in l:
p, c = S[m]
score += c + (m+1) * 100 * p
count += p
else:
X.append((score,count,l))
ans = float("inf")
for l in X:
score, count, indexes = l
if score >= G:
ans = min(ans, count)
continue
end = False
for i in list(range(D))[::-1]:
if i in indexes:
continue
if end:
break
p, c = S[i]
for _ in range(p):
count += 1
score += (i+1) * 100
if score >= G:
ans = min(ans, count)
end = True
break
print(ans)
|
p03290
|
import sys,math,collections,itertools,copy
input = sys.stdin.readline
D,G=list(map(int,input().split()))
score = []
maxScore = []
cos_per = []
for d in range(D):
p,c=list(map(int,input().split()))
tmp = [(d+1)*100]*p
tmp[-1]+=c
score.append(tmp)
maxScore.append(sum(tmp))
#cos_per.append([d+1,sum(tmp)/p])
cos_per.append([d+1,d+1])
#-最大いくつの問題セットを必要とするか-#
maxScore.sort()
tmp = 0
for idx,mS in enumerate(maxScore):
tmp += mS
if tmp >= G:
max_num = idx+1
break
#-最小でいくつの問題セットを必要とするか-#
tmp = 0
j=0
for i in range(len(maxScore)-1,-1,-1):
j+=1
tmp += maxScore[i]
if tmp >= G:
min_num = j
break
#-最小-2個はスコアが高いものを入れてよし-#
#cos_per.sort(key = lambda x:-x[1])
choice = set(range(1,D+1))
#choiceList = []
#for i in range(0,min_num-3):
# choiceList+=score[cos_per[i][0]-1]
# choice.discard(cos_per[i][0])
# max_num -=1
#-足し上げる-#
ans = float('inf')
for ch in itertools.permutations(choice,max_num):
times = 0
total = 0
flag = 0
for ci in ch:
for sc in score[ci-1]:
total += sc
times += 1
if total >= G:
ans = min(ans,times)
falg = 1
break
if flag ==1:
break
print(ans)
|
import sys,math,collections,itertools,copy
input = sys.stdin.readline
D,G=list(map(int,input().split()))
score = []
maxScore = []
cos_per = []
maxS = []
for d in range(D):
p,c=list(map(int,input().split()))
tmp = [(d+1)*100]*p
tmp[-1]+=c
score.append(tmp)
maxScore.append(sum(tmp))
maxS.append([p,sum(tmp)])
#cos_per.append([d+1,sum(tmp)/p])
cos_per.append([d+1,d+1])
#-最大いくつの問題セットを必要とするか-#
maxScore.sort()
tmp = 0
for idx,mS in enumerate(maxScore):
tmp += mS
if tmp >= G:
max_num = idx+1
break
#-最小でいくつの問題セットを必要とするか-#
tmp = 0
j=0
for i in range(len(maxScore)-1,-1,-1):
j+=1
tmp += maxScore[i]
if tmp >= G:
min_num = j
break
#-最小-2個はスコアが高いものを入れてよし-#
#cos_per.sort(key = lambda x:-x[1])
choice = set(range(1,D+1))
#choiceList = []
#for i in range(0,min_num-3):
# choiceList+=score[cos_per[i][0]-1]
# choice.discard(cos_per[i][0])
# max_num -=1
#-足し上げる-#
ans = float('inf')
for ch in itertools.permutations(choice,max_num):
times = 0
total = 0
flag = 0
for ci in ch:
if total + maxS[ci-1][1] <G:
total += maxS[ci-1][1]
times += maxS[ci-1][0]
else:
for sc in score[ci-1]:
total += sc
times += 1
if total >= G:
ans = min(ans,times)
falg = 1
break
if flag ==1:
break
print(ans)
|
p03290
|
D, G = list(map(int, input().split()))
p = [0 for i in range(D)]
c = [0 for i in range(D)]
for i in range(D):
p[i], c[i] = list(map(int, input().split()))
def dfs(s):
if len(s) == D:
ans = 1000
score = 0
times = 0
for i in range(D):
if s[i] == "1":
score += 100 * (i+1) * p[i] + c[i]
times += p[i]
if score >= G:
ans = min(ans, times)
else:
idx = s.rfind("0")
for i in range(1, p[idx]):
if score + 100 * (idx+1) * i >= G:
ans = min(ans, times+i)
break
return ans
return min(dfs(s + "0"), dfs(s+ "1"))
print((dfs("")))
|
def main():
D, G = list(map(int, input().split()))
info = [tuple(map(int, input().split())) for _ in range(D)]
ans = 100 * 10
for bit in range(1<<D):
score = 0
num_problem = 0
# complete bonus
for i in range(D):
if (bit>>i) & 1:
base = 100 * (i+1)
score += base * info[i][0] + info[i][1]
num_problem += info[i][0]
# other
for i in range(D-1, -1, -1):
if score >= G:
break
if not((bit>>i) & 1):
base = 100 * (i+1)
rest = G - score
need = (rest + base - 1) // base
if need > info[i][0] - 1:
score += base * (info[i][0] - 1)
num_problem += (info[i][0] - 1)
else:
score += base * need
num_problem += need
break
if score >= G:
ans = min(ans, num_problem)
print(ans)
if __name__ == "__main__":
main()
|
p03290
|
def main():
D, G = list(map(int, input().split()))
info = [tuple(map(int, input().split())) for _ in range(D)]
ans = 100 * 10
for bit in range(1<<D):
score = 0
num_problem = 0
# complete bonus
for i in range(D):
if (bit>>i) & 1:
base = 100 * (i+1)
score += base * info[i][0] + info[i][1]
num_problem += info[i][0]
# other
for i in range(D-1, -1, -1):
if score >= G:
break
if not((bit>>i) & 1):
base = 100 * (i+1)
rest = G - score
need = (rest + base - 1) // base
if need > info[i][0] - 1:
score += base * (info[i][0] - 1)
num_problem += (info[i][0] - 1)
else:
score += base * need
num_problem += need
break
if score >= G:
ans = min(ans, num_problem)
print(ans)
if __name__ == "__main__":
main()
|
def main():
D, G = list(map(int, input().split()))
info = [tuple(map(int, input().split())) for _ in range(D)]
ans = 100 * 10
for bit in range(1<<D):
score = 0
num_problem = 0
# complete bonus
for i in range(D):
if (bit>>i) & 1:
base = 100 * (i+1)
score += base * info[i][0] + info[i][1]
num_problem += info[i][0]
# other
if score >= G:
ans = min(ans, num_problem)
else:
for i in range(D-1, -1, -1):
if not((bit>>i) & 1):
rest = G - score
base = 100 * (i+1)
need = (rest + base -1) // base
if need <= info[i][0] - 1:
num_problem += need
score += base * need
ans = min(ans, num_problem)
break
print(ans)
if __name__ == "__main__":
main()
|
p03290
|
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string, copy
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7
ans = inf
count = 0; pro = 1
d, g = list(map(int, input().split()))
g //= 100
dp=[[inf]*(10**5*2) for i in range(11)]
dp[0][0]=0
for i in range(d):
p,c=list(map(int,input().split()));c//=100
for j in range(10**5*2):
if dp[i][j]!=inf:
dp[i+1][j]=min(dp[i+1][j],dp[i][j])
for k in range(1,p):
dp[i+1][j+(i+1)*k]=min(dp[i+1][j+(i+1)*k],dp[i][j]+k)
dp[i+1][j+(i+1)*p+c] = min(dp[i+1][j+(i+1)*p+c],dp[i][j]+p)
for i in range(g,10**5*2):
ans=min(ans,dp[d][i])
print(ans)
# for i in range(1, d+1):
# p, c = map(int, input().split())
# c //= 100
# # for key, value in tuple(D.items()):
# # print(D[key],p)
# # D[key+i*p+c//100] = min(D[key+i*p+c//100], D[key]+p)
# S = D.copy()
# for key, value in S.items():
# for k in range(1, p):
# # print(D[key+i])
# D[key+i*k] = min(D[key+i*k], S[key]+k)
# D[key+i*p+c] = min(D[key+i*p+c], S[key]+p)
# ans = inf
# for key, value in D.items():
# # print(key,value)
# if key >= g:
# ans = min(ans, value)
# print(ans)
|
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string, copy
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7
ans = inf
count = 0; pro = 1
d, g = list(map(int, input().split()))
g //= 100
dp=[[inf]*(10**5+10000) for i in range(11)]
dp[0][0]=0
for i in range(d):
p,c=list(map(int,input().split()));c//=100
for j in range(10**5+10000):
if dp[i][j]!=inf:
dp[i+1][j]=min(dp[i+1][j],dp[i][j])
for k in range(1,p):
dp[i+1][j+(i+1)*k]=min(dp[i+1][j+(i+1)*k],dp[i][j]+k)
dp[i+1][j+(i+1)*p+c] = min(dp[i+1][j+(i+1)*p+c],dp[i][j]+p)
for i in range(g,10**5+10000):
ans=min(ans,dp[d][i])
print(ans)
# for i in range(1, d+1):
# p, c = map(int, input().split())
# c //= 100
# # for key, value in tuple(D.items()):
# # print(D[key],p)
# # D[key+i*p+c//100] = min(D[key+i*p+c//100], D[key]+p)
# S = D.copy()
# for key, value in S.items():
# for k in range(1, p):
# # print(D[key+i])
# D[key+i*k] = min(D[key+i*k], S[key]+k)
# D[key+i*p+c] = min(D[key+i*p+c], S[key]+p)
# ans = inf
# for key, value in D.items():
# # print(key,value)
# if key >= g:
# ans = min(ans, value)
# print(ans)
|
p03290
|
d,g = list(map(int,input().split()))
li = [list(map(int,input().split())) for i in range(d)]
for i in range(d):
li[i].append(li[i][0]*100*(i+1) + li[i][1])
tmp = 10 ** 9
def func(x,lis,cnt):
global tmp
if x <= 0:
return cnt
else:
for i in range(d):
if i not in lis:
if x <= 100*(i+1)*(li[i][0]-1):
tmp = min(tmp,cnt + (x-1)//(100*(i+1)) + 1)
#print("{} {} {}".format(i,lis,tmp))
elif x <= li[i][2]:
tmp = min(tmp,cnt + li[i][0])
#print("{} {} {}".format(i,lis,tmp))
else:
tmp = min(tmp,func(x-li[i][2],lis+[i],cnt+li[i][0]))
#print("{} {} {}".format(i,lis,tmp))
return tmp
print((func(g,[],0)))
|
d,g = list(map(int,input().split()))
li = [list(map(int,input().split())) for i in range(d)]
ans = 10 ** 9
for i in range(2**d):
ch = bin(i)[2:]
ch = ch.zfill(d)
tmpsum = 0
cnt = 0
for j in range(d):
if ch[j] == "1":
tmpsum += li[j][0]*100*(j+1) + li[j][1]
cnt += li[j][0]
if tmpsum >= g:
ans = min(ans,cnt)
#print("{} {}".format(bin(i),cnt))
else:
ind = ch.rfind("0")
if tmpsum + (li[ind][0]-1)*100*(ind+1) >= g:
ans = min(ans,cnt+(g-tmpsum-1)//(100*(ind+1))+1)
#print("{} {} {}".format(bin(i),cnt,ans))
print(ans)
|
p03290
|
import itertools
d,g=list(map(int,input().split()))
p=[0 for _ in range(d)]
c=[0 for _ in range(d)]
l=[[] for _ in range(d)]
for i in range(d):#値を取得!
p[i],c[i]=list(map(int,input().split()))
for i in range(d):#リストつくる!
for j in range(p[i]+1):
l[i].append((i+1)*100*j)
l[i][p[i]] += c[i]
r = list(itertools.product(*l))
m = len(r)
for i in r:
if sum(i)>=g:
count = 0
for j in range(d):
count += l[j].index(i[j])
if count <= m:
m = count
print(m)
|
d,g=list(map(int,input().split()))
p=[0 for _ in range(d)]
c=[0 for _ in range(d)]
ans = 100**10
for i in range(d):#値を取得!
p[i],c[i]=list(map(int,input().split()))
for i in range(2**d):
score = 0
count = 0
horyu = 0
for j in range(d):
if ((i >> j) & 1):
score += (j+1)*p[j]*100 + c[j]
count += p[j]
else:
horyu = j #あとまわし(最高点数の1種類)
for i in range(p[horyu]):
if score >= g and count < ans:
ans = count
score += (horyu + 1) * 100
count += 1
print(ans)
|
p03290
|
# encoding: utf-8
D_MAX = 10
P_MAX = 100
num_and_pnt = lambda x: [int(x[0]), int(x[1]) // 100]
D, G = num_and_pnt(input().split())
# [pi, ci]
pc = [num_and_pnt(input().split()) + [i] for i in range(D)]
# pc.sort(key=lambda x: -((x[2] + 1) * x[0] + x[1]))
# depth-first-like search
G_tab = [(x[2] + 1) * x[0] + x[1] for x in pc]
cnt_tab = [x[0] for x in pc]
G_stack = G_tab[0]
cnt_stack = cnt_tab[0]
order = [0]
mincnt = D_MAX * P_MAX
while True:
## deepth increament (continue)
if G_stack < G:
# append lowest item (always break?)
for i in range(D):
if i not in order: break
order.append(i)
G_stack += G_tab[i]
cnt_stack += cnt_tab[i]
continue
## skip check
idx_tmp = order[-1]
G_tmp = G_stack - G_tab[idx_tmp]
cnt_tmp = cnt_stack - cnt_tab[idx_tmp]
if cnt_tmp < mincnt:
## evaluate cnt_last
x = pc[order[-1]]
cnt_last = x[0]
for i in range(x[0]):
cnt_last -= 1
G_last = (x[2] + 1) * cnt_last
# print("##", cnt_last, G_tmp + G_last, G)
if G_tmp + G_last < G: break
cnt_last += 1
## update mincnt
# print("#", order, cnt_tmp, cnt_last, G - G_tmp, "/", mincnt)
if cnt_tmp + cnt_last < mincnt: mincnt = cnt_tmp + cnt_last
## next node
order_last = order[-1] + 1
while True:
if order_last > D - 1:
idx_tmp = order[-1]
G_stack -= G_tab[idx_tmp]
cnt_stack -= cnt_tab[idx_tmp]
order.pop()
if len(order) < 1: break # end
order_last = order[-1] + 1
continue
elif order_last in order:
order_last = order_last + 1
continue
else:
idx_tmp = order[-1]
G_stack += (G_tab[order_last] - G_tab[idx_tmp])
cnt_stack += (cnt_tab[order_last] - cnt_tab[idx_tmp])
order[-1] = order_last
break
## escape
if len(order) < 1: break # end
print(mincnt)
|
# encoding: utf-8
D_MAX = 10
P_MAX = 100
num_and_pnt = lambda x: [int(x[0]), int(x[1]) // 100]
D, G = num_and_pnt(input().split())
# [pi, ci]
pc = [num_and_pnt(input().split()) for i in range(D)]
G_list = [(i + 1) * x[0] + x[1] for i, x in enumerate(pc)]
cnt_list = [x[0] for i, x in enumerate(pc)]
idx = [list(map(int, format(i, "b"))) for i in range(2 ** D)]
# i, G_comp, cnt_comp
table = [ (i, sum([((i // (2 ** j)) % 2) * G_list[j] for j in range(D)]), sum([((i // (2 ** j)) % 2) * cnt_list[j] for j in range(D)])) for i in range(2 ** D)] # very long
# print(table)
mincnt = D_MAX * P_MAX
for i, (G_last, cnt_last) in enumerate(zip(G_list, cnt_list)):
for j, G_comp, cnt_comp in [x for x in table if (((x[0] // (2 ** i)) % 2 == 0) and (x[1] <= G < x[1] + G_last) and (x[2] < mincnt))]:
# print(i, (G_last, cnt_last), j, G_comp, cnt_comp)
cnt_last_tmp = min((-((G_comp - G) // (i + 1)), cnt_last))
if cnt_comp + cnt_last_tmp < mincnt: mincnt = cnt_comp + cnt_last_tmp
print(mincnt)
|
p03290
|
# coding:utf-8
INF = float('inf')
def inpl(): return list(map(int, input().split()))
D, G = inpl()
P, C = [], []
for i in range(D):
p, c = inpl()
P.append(p)
C.append(c + 100 * (i + 1) * p)
ans = INF
for i in range(2 ** D):
point = 0
cnt = 0
rest_max = 0
for shift in range(D):
if i >> shift & 1:
cnt += P[shift]
point += C[shift]
else:
rest_max = shift
if point < G:
for j in range(P[rest_max]):
if point >= G:
break
cnt += 1
point += (rest_max + 1) * 100
else:
continue
ans = min(ans, cnt)
print(ans)
|
# coding:utf-8
import sys
INF = float('inf')
MOD = 10 ** 9 + 7
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 LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return eval(input())
# mathを使わない切り上げ
def ceil(n, m):
return -(-n//m)
d, g = LI()
contest = [LI() for _ in range(d)]
ans = INF
# Bit全探索
for bit in range(1 << d):
score = 0
cnt = 0
remain_max = -1
# 各bitが立っているか確認
for i in range(d):
if bit >> i & 1:
score += contest[i][0] * (i + 1) * 100 + contest[i][1]
cnt += contest[i][0]
continue
# コンプリートしなかった問題の中で最も得点の高い問題をメモ
remain_max = i
if score >= g:
ans = min(ans, cnt)
continue
need = ceil((g - score) // 100, remain_max + 1)
if need >= contest[remain_max][0]:
continue
ans = min(ans, cnt + need)
print(ans)
|
p03290
|
d, g = list(map(int, input().split()))
pc = [list(map(int, input().split())) for i in range(d)]
ans = float("inf")
for bit in range(1 << d):
count = 0
sum = 0
nokori = set(range(1, d + 1))
for i in range(d):
if bit & (1 << i):
sum += pc[i][0] * (i + 1) * 100 + pc[i][1]
count += pc[i][0]
nokori.discard(i + 1)
if sum < g:
use = max(nokori)
count += min(pc[use - 1][0], -(-(g - sum) // (use * 100)))
sum += min(pc[use - 1][0], -(-(g - sum) // (use * 100))) * use * 100
if sum >= g:
ans = min(ans, count)
print(ans)
|
def dfs(i, sum, count, nokori):
global ans
if i == d:
if sum < g:
use = max(nokori)
n = min(pc[use - 1][0], -(-(g - sum) // (use * 100)))
count += n
sum += n * use * 100
if sum >= g:
ans = min(ans, count)
return 0
dfs(i + 1, sum, count, nokori)
dfs(i + 1, sum + pc[i][0] * (i + 1) * 100 + pc[i][1], count + pc[i][0], nokori - {i + 1})
d, g = list(map(int, input().split()))
pc = [list(map(int, input().split())) for i in range(d)]
ans = float("inf")
dfs(0, 0, 0, set(range(1, d + 1)))
print(ans)
|
p03290
|
#abc104c all green
d, g = list(map(int, input().split()))
pc = [list(map(int, input().split())) for _ in range(d)]
all_sum = []
for bit in range(1<<d):
s = 0
a = 0
rest = []
for i in range(d):
if bit & (1<<i):
s += pc[i][0]*100*(i+1) + pc[i][1]
a += pc[i][0]
else :
rest.append(i)
if s >= g :
all_sum.append(a)
else :
k = max(rest)
diff = g - s
for j in range(pc[k][0]):
if j*(k+1)*100 >= diff:
all_sum.append(a+j)
print((min(all_sum)))
|
def dfs(i, sum, count, rest):
global ans
if i == d:
if sum < g:
rest_max = max(rest)
n = min(l[rest_max-1][0], -(-(g-sum)//(rest_max*100)))
count += n
sum += n * rest_max * 100
if sum >= g:
ans = min(ans, count)
else :
dfs(i+1, sum, count, rest) #二分岐のうち解かない選択
dfs(i+1, sum + l[i][0]*(i+1)*100+l[i][1], count + l[i][0], rest - {i+1}) #解く選択
d, g = list(map(int, input().split()))
l = [list((list(map(int, input().split())))) for _ in range(d)]
ans = float("inf")
dfs(0, 0, 0, set(range(1, d+1)))
print(ans)
|
p03290
|
D, G = list(map(int, input().split()))
pc = [list(map(int, input().split())) for i in range(D)]
G /= 100
C = 2e3
N = len(pc)
for i in range(2 ** N):
p = 0
c = 0
for j in range(N):
if i >> j & 1:
p += pc[j][0] * (j + 1) + pc[j][1] / 100
c += pc[j][0]
if p >= G:
C = min(c, C)
continue
for j in range(N-1, -1, -1):
if not i >> j & 1:
for k in range(pc[j][0] - 1):
p += j + 1
c += 1
if p >= G:
break
if p >= G:
break
if p >= G:
C = min(c, C)
continue
print(C)
|
D, G = list(map(int, input().split()))
G = int(G / 100)
pc = [list(map(int, input().split())) for _ in range(D)]
N = 10 ** 9
for bit in range(2 ** D):
S = 0
c = 0
A = True
a = -1
for i in range(D - 1, -1, -1):
if bit & (1 << i):
S += (i + 1) * pc[i][0] + int(pc[i][1] / 100)
c += pc[i][0]
elif A:
a = i
A = False
if a != -1:
for i in range(1, pc[a][0]):
if S >= G:
break
S += a + 1
c += 1
if S >= G:
N = min(N, c)
print(N)
|
p03290
|
import math
d,g = [int(i) for i in input().split()]
P = []
C = []
for i in range(d):
p,c = [int(i) for i in input().split()]
P.append(p)
C.append(c)
# cnt = 0
# def count():
# global cnt
# cnt+=1
# print(cnt)
def flag(point,P,now):
if point+100*(now+1)*P >= g: return 1
else: return 0
m = 10**9
def score(point = 0, n = 0, now=-1, done=[]):
global m
if m <= n: return
elif point >= g: m = n
elif flag(point,P[now],now):
n += math.ceil((g-point)/(100*(now+1)))
if m > n: m = n
else:
if now == -1:
for i in range(d):
score(point, n, i, done)
elif m <= n+P[now]: return
else:
done = done[:]
done.append(now)
nxtp = point+P[now]*100*(now+1) + C[now]
for i in range(d):
if not i in done:
score(nxtp, n + P[now], i, done)
score()
print(m)
|
import math
d,g = [int(i) for i in input().split()]
P = []
C = []
for i in range(d):
p,c = [int(i) for i in input().split()]
P.append(p)
C.append(c)
# cnt = 0
# def count():
# global cnt
# cnt+=1
# print(cnt)
def flag(point,P,now):
if point+100*(now+1)*(P-1) >= g: return 1
elif point+100*(now+1)*P + C[now] >= g: return 2
else: return 0
m = 10**9
def score(point = 0, n = 0, now=-1, remain = list(range(d))):
global m
if m <= n: return
elif now == -1:
for i in remain:
score(point, n, i, remain)
elif point >= g: m = n
elif flag(point,P[now],now) == 1:
n += math.ceil((g-point)/(100*(now+1)))
if m > n: m = n
elif flag(point,P[now],now) == 2:
n += P[now]
if m > n: m = n
else:
if m <= n+P[now]: return
else:
remain = remain[:]
remain.remove(now)
nxtp = point + P[now]*100*(now+1) + C[now]
for i in remain:
score(nxtp, n + P[now], i, remain)
score()
print(m)
|
p03290
|
def main():
D, G, *pc = list(map(int, open(0).read().split()))
p = pc[::2]
c = pc[1::2]
ans = 1e9 + 7
# 2 ** D - 1 まで
for b in range(2 ** D):
num = 0
pnt = 0
# コンプリートしない MAX
x = None
# 得点が高い方から
for i in range(D - 1, -1, -1):
# i 番目 の フラグ が 立っている
if b >> i & 1:
num += p[i]
# コンプリートする
pnt += c[i] + 100 * (i + 1) * p[i]
elif x is None:
x = i
# コンプリート オール
# または 既に 目標の 総合スコア に到達
if x is None or G <= pnt:
ans = min(ans, num)
# コンプリートしない MAX で 目標の 総合スコア に到達
elif G < (100 * (x + 1)) * p[x] + pnt:
ans = min(ans, num - (-(G - pnt) // (100 * (x + 1))))
print(ans)
return
main()
|
def main():
D, G, *pc = list(map(int, open(0).read().split()))
p = pc[::2]
c = pc[1::2]
ans = 1e9 + 7
# コンプリート
comp = [c[i] + 100 * (i + 1) * p[i] for i in range(D)]
# 2 ** D - 1 まで
for b in range(2 ** D):
num = 0
pnt = 0
# コンプリートしない MAX
x = None
# 得点が高い方から
for i in range(D - 1, -1, -1):
# i 番目 の フラグ が 立っている
if b >> i & 1:
num += p[i]
# コンプリートする
pnt += comp[i]
elif x is None:
x = i
# コンプリート オール
# または 既に 目標の 総合スコア に到達
if x is None or G <= pnt:
ans = min(ans, num)
# コンプリートしない MAX で 目標の 総合スコア に到達
elif G < (100 * (x + 1)) * p[x] + pnt:
ans = min(ans, num - (-(G - pnt) // (100 * (x + 1))))
print(ans)
return
main()
|
p03290
|
D, G = [int(_) for _ in input().split()]
PC = [[int(_) for _ in input().split()] for i in range(D)]
P = [p for p, c in PC]
C = [c for p, c in PC]
from heapq import *
h = []
heappush(h, (0, 0, (0,)*D))
result = 0
ef = {}
while h:
t, score, pat = heappop(h)
# print(t, score, pat)
if score >= G:
result = t
break
def add(i, pat, d):
pat1 = list(pat)
if pat1[i] +d <= P[i]:
pat1[i] += d
pat1 = tuple(pat1)
if not pat1 in ef:
t1 = t + d
score1 = score + (i+1)*100*d
if pat1[i] == P[i]:
score1 += C[i]
ef[pat1] = t
heappush(h, (t1, score1, pat1))
for i in range(D-1, -1, -1):
if pat[i] < P[i]:
add(i, pat, 1)
break
for i in range(D):
if pat[i] + 1 < P[i]:
add(i, pat, P[i] - pat[i])
print(result)
|
D, G = [int(_) for _ in input().split()]
PC = [tuple(int(_) for _ in input().split()) for i in range(D)]
from itertools import product
def calc(D, G, PC, es):
r = 0
k = None
result = 0
for i, e, pc in zip(list(range(D)), es, PC):
if e:
r += (i+1) * 100 * pc[0] + pc[1]
result += pc[0]
else:
k = i
if r >= G:
return result, r
if not k is None:
d = (k+1)*100
p = PC[k][0]
if r + d * (p - 1) >= G:
n = (G - r + d - 1) // d
result += n
r += n * d
return result, r
return None, None
result = 10**20
for es in product((0, 1), repeat=D):
r, score = calc(D, G, PC, es)
#print(D, G, PC, es, r, score)
if not r is None:
result = min(result, r)
print(result)
|
p03290
|
D, G = list(map(int, input().split()))
P, C = [], []
for _ in range(D):
p, c = list(map(int, input().split()))
P.append(p); C.append(c)
ans = float('inf')
for bit in range(2**D):
is_solve = [ 0 for _ in range(D) ]
score, solve_num = 0, 0
# i 番目の bit が立っている => 100(i+1)点をつけられた p_i 問を全完する
for i in range(D):
if (bit >> i) & 1:
score += (100 * (i+1) * P[i] + C[i])
solve_num += P[i]
is_solve[i] += P[i]
for i in range(D-1, -1, -1):
if score >= G:
break
while is_solve[i] < P[i]:
score += 100*(i+1)
solve_num += 1
is_solve[i] += 1
if score >= G:
break
ans = min(ans, solve_num)
print(ans)
|
D, G = list(map(int, input().split()))
P, C = [], []
for _ in range(D):
p, c = list(map(int, input().split()))
P.append(p); C.append(c)
ans = float('inf')
for bit in range(2**D):
score, solve_num = 0, 0
for i in range(D):
if (bit >> i) & 1:
score += (100 * (i+1) * P[i] + C[i])
solve_num += P[i]
for i in range(D-1, -1, -1):
if score >= G:
break
if (bit >> i) & 1:
continue
for j in range(P[i]):
score += 100*(i+1)
solve_num += 1
if score >= G:
break
ans = min(ans, solve_num)
print(ans)
|
p03290
|
D, G = list(map(int, input().split()))
problem = []
bonus_score = []
for i in range(D):
pi, ci = list(map(int, input().split()))
problem.append(pi)
bonus_score.append(ci)
total_problem = sum(problem)
dp= [[0 for k in range(total_problem + 1)] for i in range(D+1)]
for i in range(D):
for k in range(total_problem + 1):
for j in range(min(problem[i], k) + 1):
dp[i+1][k] = max(dp[i+1][k], dp[i][k - j] + (i + 1) * 100 * j + (j//problem[i]) * bonus_score[i])
ans = 0
while dp[D][ans] < G:
ans += 1
print(ans)
|
D, G = list(map(int, input().split()))
problem = []
bonus = []
for i in range(D):
pi, ci = list(map(int, input().split()))
problem.append(pi)
bonus.append(ci)
ans = float('inf')
for S in range(1 << D): # Sは2^Dの元
score = sum([(problem[j] * 100 * (j + 1) + bonus[j]) * ((S >> j) & 1) for j in range(D)])
count = sum([problem[j] * ((S >> j) & 1) for j in range(D)])
if score >= G:
ans = min(ans,count)
else:
for i in range(D):
if (S >> i) & 1 == 0 and score + problem[i] * 100 * (i + 1) >= G: #Sにiが含まれないとき
count_2 = count + (G - score + (100 * (i + 1)) - 1) // (100 * (i + 1))
ans = min(ans, count_2)
print(ans)
|
p03290
|
difficulties, goal = list(map(int, input().split()))
pcs = [list(map(int, input().split())) for _ in range(difficulties)]
dp = [[0] * 1102 for _ in range(difficulties + 1)]
for d, pc in enumerate(pcs, 1):
problem, complete = pc
score = [x*100*d for x in range(problem)] + [problem*100*d+complete] +[0] * 1001
for i in range(1, 1001):
for j in range(0, i + 1):
if i - j > problem:
dp[d][i] = max(dp[d][i], dp[d - 1][j])
else:
dp[d][i] = max(dp[d][i], dp[d-1][j] + score[i-j])
for i, a in enumerate(dp[difficulties]):
if a >= goal:
print(i)
exit()
|
difficulties, goal = list(map(int, input().split()))
pcs = [list(map(int, input().split())) for _ in range(difficulties)]
dp = [[0] * 1102 for _ in range(difficulties + 1)]
total_problem = 0
for d, pc in enumerate(pcs, 1):
problem, complete = pc
total_problem += problem
score = {x: x*100*d for x in range(problem)}
score[problem] = problem * 100 * d +complete
for i in range(1, total_problem + 1):
for j in range(0, i + 1):
if i - j > problem:
dp[d][i] = max(dp[d][i], dp[d - 1][j])
else:
dp[d][i] = max(dp[d][i], dp[d-1][j] + score[i-j])
for i, a in enumerate(dp[difficulties]):
if a >= goal:
print(i)
exit()
|
p03290
|
difficulties, goal = list(map(int, input().split()))
pcs = [list(map(int, input().split())) for _ in range(difficulties)]
dp = [[0] * 1102 for _ in range(difficulties + 1)]
total_problem = 0
for d, pc in enumerate(pcs, 1):
problem, complete = pc
total_problem += problem
score = {x: x*100*d for x in range(problem)}
score[problem] = problem * 100 * d +complete
for i in range(1, total_problem + 1):
for j in range(0, i + 1):
if i - j > problem:
dp[d][i] = max(dp[d][i], dp[d - 1][j])
else:
dp[d][i] = max(dp[d][i], dp[d-1][j] + score[i-j])
for i, a in enumerate(dp[difficulties]):
if a >= goal:
print(i)
exit()
|
difficulties, goal = list(map(int, input().split()))
pcs = [list(map(int, input().split())) for _ in range(difficulties)]
total_problem = 0
new_dp = [0] * 1001
for d, pc in enumerate(pcs, 1):
dp = new_dp[:]
problem, complete = pc
total_problem += problem
score = {x: x*100*d for x in range(problem)}
score[problem] = problem * 100 * d +complete
for i in range(1, total_problem + 1):
for j in range(0, i + 1):
if i - j > problem:
continue
else:
new_dp[i] = max(new_dp[i], dp[j] + score[i-j])
for i, a in enumerate(new_dp):
if a >= goal:
print(i)
exit()
|
p03290
|
from math import ceil
D, G = list(map(int,input().split()))
pc = [list(map(int,input().split())) for i in range(D)]
ans = float("inf")
for bit in range(1 << D):
cnt = 0
sum = 0
remain = set(range(1,D+1))
for i in range(D):
if bit & (1 << i):
cnt += pc[i][0]
sum += pc[i][0]*(i+1)*100 + pc[i][1]
remain.discard(i+1)
if sum < G:
use = max(remain)
n = min(pc[use-1][0], ceil((G-sum)/(use*100)))
cnt += n
sum += n*use*100
if sum >= G:
ans = min(ans,cnt)
print(ans)
|
def dfs(i, sum, count, nokori):
global ans
if i == d:
# G 点に満たなければ nokori のうち一番大きいものを解く
if sum < g:
use = max(nokori)
# 解く問題が問題数を超えないように注意
n = min(pc[use - 1][0], -(-(g - sum) // (use * 100)))
count += n
sum += n * use * 100
if sum >= g:
ans = min(ans, count)
else:
# 総合スコア、解いた問題数、まだ解いてない問題を更新
dfs(i + 1, sum, count, nokori)
dfs(i + 1, sum + pc[i][0] * (i + 1) * 100 + pc[i][1], count + pc[i][0], nokori - {i + 1})
d, g = list(map(int, input().split()))
pc = [list(map(int, input().split())) for i in range(d)]
ans = float("inf")
dfs(0, 0, 0, set(range(1, d + 1)))
print(ans)
|
p03290
|
import sys
import math
input = sys.stdin.readline
def I():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def LI():
return list(MI())
inf = float("inf")
def main():
d, g = MI()
pc = [LI() for _ in range(d)]
ans = inf
for bit in range(2 << d):
c = 0
score = 0
for i in range(d):
if bit & (1 << i):
c += pc[i][0]
score += pc[i][0] * 100 * (i + 1) + pc[i][1]
if score >= g:
ans = min(ans, c)
else:
for i in reversed(list(range(d))):
if bit & (1 << i):
continue
res = math.ceil((g - score) / (100 * (i + 1)))
if res < pc[i][0]:
ans = min(ans, c + res)
break
print(ans)
if __name__ == "__main__":
main()
|
import sys
import math
input = sys.stdin.readline
def I():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def LI():
return list(MI())
inf = float("inf")
def main():
d, g = MI()
pc = [LI() for _ in range(d)]
ans = inf
for bit in range(1 << d):
c = 0
score = 0
for i in range(d):
if bit & (1 << i):
c += pc[i][0]
score += pc[i][0] * 100 * (i + 1) + pc[i][1]
if score >= g:
ans = min(ans, c)
else:
for i in reversed(list(range(d))):
if bit & (1 << i):
continue
res = math.ceil((g - score) / (100 * (i + 1)))
if res < pc[i][0]:
ans = min(ans, c + res)
break
print(ans)
if __name__ == "__main__":
main()
|
p03290
|
D,G=list(map(int,input().split()))
G//=100
p=[0]*D
c=[0]*D
for i in range(D):
p[i],c[i]=list(map(int,input().split()))
c[i]//=100
ans=10**10
for bit in range(2**D):
score=G
problems=0
SET=set([i for i in range(D)])
for g in range(bit):
if (bit>>g)&1:
score-=(g+1)*p[g]+c[g]
problems+=p[g]
SET.remove(g)
if score<=0:
ans=min(ans,problems)
else:
#SETが空集合になる時は全ての問題を解いた時であり、全ての問題を解けば必ずscoreは負になるので
#「ValueError: max() arg is an empty sequence」は防げる。
MAX=max(SET)
for _ in range(p[MAX]):
score-=(MAX+1)
problems+=1
if score<=0:
ans=min(ans,problems)
break
print(ans)
|
D,G=list(map(int,input().split()))
G//=100
p=[0]*D
c=[0]*D
for i in range(D):
p[i],c[i]=list(map(int,input().split()))
c[i]//=100
ans=10**10
for bit in range(2**D):
score=G
problems=0
SET=set([i for i in range(D)])
for g in range(D):
if (bit>>g)&1:
score-=(g+1)*p[g]+c[g]
problems+=p[g]
SET.remove(g)
if score<=0:
ans=min(ans,problems)
else:
#SETが空集合になる時は全ての問題を解いた時であり、全ての問題を解けば必ずscoreは負になるので
#「ValueError: max() arg is an empty sequence」は防げる。
MAX=max(SET)
for _ in range(p[MAX]):
score-=(MAX+1)
problems+=1
if score<=0:
ans=min(ans,problems)
break
print(ans)
|
p03290
|
d,g=list(map(int,input().split()))
g=g//100
p_list=[0]
c_list=[0]
for i in range(d):
p,c=list(map(int,input().split()))
p_list.append(p)
c_list.append(c//100)
dp=[]
for i in range(d+1):
sub_list=[]
for j in range(g+1):
sub_list.append(10**9)
dp.append(sub_list)
dp[0][0]=0
for i in range(1,d+1):
for j in range(g+1):
for k in range(p_list[i]+1):
if k==p_list[i]:
if j-i*k-c_list[i]>=0:
dp[i][j]=min(dp[i][j],dp[i-1][j-i*k-c_list[i]]+k)
else:
dp[i][j]=min(dp[i][j],dp[i-1][0]+k)
else:
if j-i*k>=0:
dp[i][j]=min(dp[i][j],dp[i-1][j-i*k]+k)
else:
dp[i][j]=min(dp[i][j],dp[i-1][0]+k)
print((dp[d][g]))
|
d,g=list(map(int,input().split()))
g=g//100
p_list=[]
c_list=[]
s_list=[]
for i in range(d):
p,c=list(map(int,input().split()))
c=c//100
p_list.append(p)
c_list.append(c)
s_list.append(p*(i+1)+c)
Min=1000
for i in range(2**d):
Sum=0
Num=0
for j in range(d):
if (i>>j)&1==1:
Sum=Sum+s_list[j]
Num=Num+p_list[j]
else:
M=j
if Sum>=g:
if Num<Min:
Min=Num
else:
r=((g-Sum)+M)//(M+1)
if r<=p_list[M]:
Num=Num+r
if Num<Min:
Min=Num
print(Min)
|
p03290
|
D,G = list(map(int,input().split()))
P = []
C = []
for i in range(D) :
p,c = list(map(int,input().split()))
P.append(p)
C.append(c)
ans = float("inf")
for i in range(1 << D) : # 2**D
ct = 0 #cost
score = 0
for j in range(D) :
if (i >> j) & 1 : #bit全探索
score += C[j] #bonus
score += P[j] * (j+1) * 100 #normal
ct += P[j] #cost
for j in range(D-1,-1,-1) : #降順
if score >= G :
break
if (i >> j) & 1 : #すでに計算された得点帯を除外
continue
g = (j+1)*100
got = (G-score)//g
score += min(got,P[j])*g
ct += min(got,P[j])
ans = min(ans, ct)
print(ans)
|
D,G = list(map(int,input().split()))
L = [list(map(int,input().split())) for i in range(D)]
ans = float("inf")
for bit in range(2 ** D) :
score = 0
AC = 0
for k in range(D) :
if bit & (1 << k) :
p,c = L[k]
score += c
AC += p
score += p*(k+1)*100
if score >= G :
ans = min(ans,AC)
continue
for k in range(D-1,-1,-1) :
if bit & (1 << k) :
continue
p,c = L[k]
if (score + p*(k+1)*100) < G :
score += p*(k+1)*100
AC += p
else :
rem = G - score
AC += rem // ((k+1)*100)
if rem % ((k+1)*100) != 0 :
AC += 1
ans = min(ans,AC)
break
print(ans)
|
p03290
|
d, g = [int(i) for i in input().split()]
p = [0] + [[int(i) for i in input().split()] for _ in range(d)]
def recursive(d, g):
if d == 0:
return 10 ** 9
n = min(g // (100 * d), p[d][0])
t = 100 * d * n
# Full
if n == p[d][0]:
t += p[d][1]
# Partial
if t < g:
n += recursive(d-1, g-t)
return min(n, recursive(d-1, g))
def bit(d, g):
ans = 10 ** 9
for i in range(2 ** d):
b = '-' + format(i, '0{}b'.format(d))
last_zero_index = 0
tmp_ans = 0
total_score = 0
for j in range(1, d+1):
if b[j] == '1':
total_score += p[j][0] * (100 * (j))
total_score += p[j][1]
tmp_ans += p[j][0]
else:
last_zero_index = j
if total_score < g:
diff = g - total_score
q = diff // (100 * last_zero_index)
r = diff % (100 * last_zero_index)
if r != 0:
q += 1
if q > p[last_zero_index][0]:
continue
else:
tmp_ans += q
ans = min(ans, tmp_ans)
return ans
#solve = recursive
solve = bit
print((solve(d, g)))
|
d, g = [int(i) for i in input().split()]
p = [0] + [[int(i) for i in input().split()] for _ in range(d)]
def recursive(d, g):
if d == 0:
return 10 ** 9
n = min(g // (100 * d), p[d][0])
t = 100 * d * n
# Full
if n == p[d][0]:
t += p[d][1]
# Partial
if t < g:
n += recursive(d-1, g-t)
return min(n, recursive(d-1, g))
def bit(d, g):
ans = 10 ** 9
for i in range(2 ** d):
b = '-' + format(i, '0{}b'.format(d))
last_zero_index = 0
tmp_ans = 0
total_score = 0
for j in range(1, d+1):
if b[j] == '1':
total_score += p[j][0] * (100 * (j))
total_score += p[j][1]
tmp_ans += p[j][0]
else:
last_zero_index = j
if total_score < g:
diff = g - total_score
q = diff // (100 * last_zero_index)
r = diff % (100 * last_zero_index)
if r != 0:
q += 1
if q > p[last_zero_index][0]:
continue
else:
tmp_ans += q
ans = min(ans, tmp_ans)
return ans
solve = recursive
#solve = bit
print((solve(d, g)))
|
p03290
|
def rec(i, g, count, rem):
global ans
if i == D:
# 総得点がGを超えていなければ、remの中の最高配点の問題を解く
if g < G:
# 解く問題
use = max(rem)
c = min(pc[use-1][0], -(-(G-g) // (use*100)))
count += c
g += use*100 * c
if g >= G:
ans = min(ans, count)
else:
# 全部解かない
rec(i+1, g, count, rem)
# 全部解く
rec(i+1, g+(i+1)*100*pc[i][0]+pc[i][1], count+pc[i][0], rem-{i+1})
# 入力
D, G = list(map(int, input().split()))
pc = [[int(i) for i in input().split()] for j in range(D)]
# 解いてない問題リスト
rem = set(range(1, D+1))
ans = float("inf")
rec(0, 0, 0, rem)
print(ans)
|
def rec(i, g, count, rem):
global ans
if i == 0:
# 総得点がGを超えていなければ、remの中の最高配点の問題を解く
if g < G:
# 解く問題
use = max(rem)
c = min(pc[use-1][0], -(-(G-g) // (use*100)))
count += c
g += use*100 * c
if g >= G:
ans = min(ans, count)
else:
# 全部解かない
rec(i-1, g, count, rem)
# 全部解く
rem[i] = 0
rec(i-1, g+i*100*pc[i-1][0]+pc[i-1][1], count+pc[i-1][0], rem)
rem[i] = i
# 入力
D, G = list(map(int, input().split()))
pc = [[int(i) for i in input().split()] for j in range(D)]
# 解いてない問題リスト
rem = [i for i in range(D+1)]
ans = float("inf")
rec(D, 0, 0, rem)
print(ans)
|
p03290
|
import math
from itertools import permutations
d,g = list(map(int,input().split()))
x = []
for i in range(d):
x1,y1=[int(i) for i in input().split()]
x.append([x1,y1])
zy = [i for i in range(1,d+1)]
zyu = list(permutations(zy, d))
ans2 = 100000000000000000000000
gou = g+0
for i in zyu:
ans = 0
g = gou +0
while g > 0:
for j in i:
if g <= 0:
break
dai = x[-j][0]
if g > (d-j+1)*100*dai:
g-= ((d-j+1)*100*dai +x[-j][1])
ans += dai
continue
else:
ans += math.ceil(g/((d-j+1)*100))
g = 0
g -= x[-j][1]
ans2 = min(ans,ans2)
print((int(ans2)))
|
import math
from itertools import combinations
d,g = list(map(int,input().split()))
x = []
for i in range(d):
x1,y1=[int(i) for i in input().split()]
x.append([x1,y1])
zy = [i for i in range(1,d+1)]
zyu = []
for i in range(d+1):
zyu.extend(list(combinations(zy, i)))
ans2 = 100000000000000000000000
gou = g+0
for i in zyu:
ans = 0
g = gou +0
for j in i:
g -= (x[j-1][0] * j*100 + x[j-1][1])
ans += x[j-1][0]
if g >0:
y = d+0
while y in i:
y -= 1
a = x[y-1][0]
if g > a*y*100:
continue
ans += math.ceil(g/(y*100))
ans2 = min(ans,ans2)
print(ans2)
|
p03290
|
D, G = list(map(int,input().split()))
pc = [list(map(int,input().split())) for _ in range(D)]
ans = 1e9
for i in range(1 << D):
cnt = 0
point = 0
for j in range(D):
if(((i >> j) & 1) == 1):
point += pc[j][0]*100*(j+1) + pc[j][1]
cnt += pc[j][0]
else:
tmp = j
if(point < G):
x = G - point
if((pc[tmp][0]-1)*(tmp+1)*100 < x):
continue
cnt += -(-x//(100*(tmp+1)))
ans = min(ans, cnt)
print(ans)
|
D, G = list(map(int,input().split()))
PC = [list(map(int,input().split())) for _ in range(D)]
ans = 1e9
for i in range(1 << D):
point = 0
cnt = 0
for j in range(D):
if(((i >> j) & 1) == 1):
point += PC[j][0]*(j+1)*100 + PC[j][1]
cnt += PC[j][0]
else:
tmp = j
if(point < G):
x = G - point
if((PC[tmp][0]-1)*(tmp+1)*100 < x):
continue
cnt += -(-x//(100*(tmp+1)))
ans = min(ans, cnt)
print(ans)
|
p03290
|
D, G = list(map(int,input().split()))
PC = [list(map(int,input().split())) for _ in range(D)]
ans = 1e9
for i in range(1 << D):
point = 0
cnt = 0
for j in range(D):
if(((i >> j) & 1) == 1):
point += PC[j][0]*(j+1)*100 + PC[j][1]
cnt += PC[j][0]
else:
tmp = j
if(point < G):
x = G - point
if((PC[tmp][0]-1)*(tmp+1)*100 < x):
continue
cnt += -(-x//(100*(tmp+1)))
ans = min(ans, cnt)
print(ans)
|
D, G = list(map(int,input().split()))
PC = [0]+[list(map(int,input().split())) for _ in range(D)]
def dfs(d, g):
if(d == 0):
return 1e9
x = min(g//(100*d), PC[d][0])
point = x*100*d
if(x == PC[d][0]):
point += PC[d][1]
if(point < g):
x += dfs(d-1, g-point)
return min(x, dfs(d-1, g))
print((dfs(D, G)))
|
p03290
|
import itertools
import math
d, g = list(map(int, input().split()))
ls = [list(map(int, input().split())) for _ in range(d)]
res = float('inf')
for indices in itertools.permutations(list(range(d))):
count = 0
s = 0
for i in indices:
p, c = ls[i]
if s + 100 * (i + 1) * p >= g:
count += math.ceil((g - s) / (100 * (i + 1)))
break
else:
count += p
if count >= res:
break
s += 100 * (i + 1) * p + c
if s >= g:
break
res = min(res, count)
print(res)
|
import itertools
import math
d, g = list(map(int, input().split()))
ls = [[100 * (i + 1)] + list(map(int, input().split())) for i in range(d)]
s0 = [a * p for a, p, _ in ls]
s1 = [a * p + c for a, p, c in ls]
res = float('inf')
for indices in itertools.permutations(list(range(d))):
count = 0
s = 0
for i in indices:
if s + s0[i] >= g:
count += math.ceil((g - s) / (100 * (i + 1)))
break
else:
count += ls[i][1]
if count >= res:
break
s += s1[i]
if s >= g:
break
res = min(res, count)
print(res)
|
p03290
|
D, G = list(map(int, input().split(' ')))
p_list = list()
c_list = list()
for _ in range(D):
p, c = list(map(int, input().split(' ')))
p_list.append(p)
c_list.append(c)
num_prob_list = [0] * D
min_prob_num_sum = sum(p_list)
def dfs(prob_index=-1, prob_num=0, current_prob_num_sum=0, current_score=0):
"""
Returns whether score >= G with local minimum of problems.
"""
global min_prob_num_sum
if prob_index >= 0:
current_prob_num_sum += prob_num
if current_prob_num_sum >= min_prob_num_sum:
return False
num_prob_list[prob_index] = prob_num
current_score += 100 * (prob_index + 1) * prob_num
if prob_num == p_list[prob_index]:
current_score += c_list[prob_index]
if current_score >= G:
min_prob_num_sum = current_prob_num_sum
# print(num_prob_list[:(prob_index + 1)])
# print(current_score)
return True
next_prob_index = prob_index + 1
if next_prob_index > D - 1:
return False
for next_prob_num in range(p_list[next_prob_index] + 1):
if dfs(next_prob_index, next_prob_num, current_prob_num_sum, current_score):
break
dfs()
print(min_prob_num_sum)
|
import itertools
import math
D, G = list(map(int, input().split(' ')))
p_list = list()
c_list = list()
for _ in range(D):
p, c = list(map(int, input().split(' ')))
p_list.append(p)
c_list.append(c)
ans = sum(p_list)
pattern_list = itertools.product([0, 1], repeat=D)
for pattern in pattern_list:
score = 0
prob_num = 0
# Solve all problems with bit `1`
score += sum([bit * (100 * (index + 1) * p_list[index] + c_list[index]) for index, bit in enumerate(pattern)])
prob_num += sum([bit * p_list[index] for index, bit in enumerate(pattern)])
# Solve problems partially with bit `0'
if score < G:
for index in range(D - 1, -1, -1):
if pattern[index] == 1:
# skip because these cases are already counted
continue
required_num = math.ceil((G - score) / (100 * (index + 1)))
sol_num = min([p_list[index] - 1, required_num])
score += 100 * (index + 1) * sol_num
prob_num += sol_num
if score >= G:
break
# update answer
if score >= G:
ans = min([ans, prob_num])
print(ans)
|
p03290
|
D, G = [int(n) for n in input().split()]
score_table = []
for i in range(1, D+1):
p, c = [int(n) for n in input().split()]
score_table.append([i*100, p, c])
min_count = sum([l[1] for l in score_table])
#print(min_count)
for bit in range(1<<D):
score = 0
count = 0
for i in range(D):
if bit & (1<<i):
score += score_table[i][0] * score_table[i][1] + score_table[i][2]
count += score_table[i][1]
if score >= G:
min_count = min(min_count, count)
else:
additional = []
for j in range(D):
if not bit & (1<<j):
additional.append(score_table[j])
additional_ = sorted(additional, key=lambda x:x[0], reverse=True)
#print(additional_)
# for i in additional_:
# if i[1] > 1:
# add_score = i
# break
add_score = additional_[0]
for k in range(add_score[1]-1):
score += add_score[0]
count += 1
if score >= G:
min_count = min(min_count, count)
print(min_count)
|
D, G = [int(n) for n in input().split()]
score_table = []
for i in range(1, D+1):
p, c = [int(n) for n in input().split()]
score_table.append([i*100, p, c])
min_count = sum([l[1] for l in score_table])
#print(min_count)
for bit in range(1<<D):
score = 0
count = 0
for i in range(D):
if bit & (1<<i):
score += score_table[i][0] * score_table[i][1] + score_table[i][2]
count += score_table[i][1]
if score >= G:
min_count = min(min_count, count)
else:
additional = []
for j in range(D):
if not bit & (1<<j):
additional.append(score_table[j])
additional_ = sorted(additional, key=lambda x:x[0], reverse=True)
#print(additional_)
# for i in additional_:
# if i[1] > 1:
# add_score = i
# break
#add_score = additional_[0]
for k in range(additional_[0][1]-1):
score += additional_[0][0]
count += 1
if score >= G:
min_count = min(min_count, count)
print(min_count)
|
p03290
|
import random
import bisect
import math
option = 0 # 0:PSO 1:CFA 2:CFArank
max_or_min = 0 # 0:minimize 1:maxmize
iter=3
N = 50 #粒子の数
T = 1000 #世代数(ループの回数)
maximum=1
minimum=0
dimension, limit = [int(i) for i in input().split()]
pi = [0 for i in range(dimension)]
ci = [0 for i in range(dimension)]
for i in range(dimension):
pi[i], ci[i] = [int(i) for i in input().split()]
tot = [pi[i] * (i+1) * 100 + ci[i] for i in range(dimension)]
#print(pi)
#print(ci)
#print(tot)
#--------粒 子 群 最 適 化------------------------------
#評価関数
def criterion(x):
z = sum([pi[i] * x[i] for i in range(dimension)])
z2 = sum([tot[i] * x[i] for i in range(dimension)])
k = -1
for i in range(dimension):
if x[dimension -1 -i] == 0:
k = dimension -1 -i
break
if k != -1:
for i in range(pi[k]):
if limit > z2:
z += 1
z2 += (k+1) * 100
else:
break
if limit > z2:
z = 10000
return z
#粒子の位置の更新を行う関数
def update_position(x, v, x_min, x_max):
# new_x = [x_min[i] if x[i]+ v[i] < x_min[i] else x_max[i] if x[i]+ v[i] > x_max[i] else x[i]+ v[i] for i in range(dimension)]
new_x = [1 if random.uniform(0, 1)< 1/(1+math.e**(-v[i])) else 0 for i in range(dimension)]
return new_x
#粒子の速度の更新を行う関数
def update_velocity(x, v, p, g, w, ro_max=1.0, c1=2.00, c2=0.75):
#パラメーターroはランダムに与える
phi=c1+c2
K=2/abs(2-phi-(phi*phi-4*phi)**0.5)
#粒子速度の更新を行う
if option!=0:
new_v = [K * ( w * v[i] + c1 * random.uniform(0, ro_max) * (p[i] - x[i]) + c2 * random.uniform(0, ro_max) * (g[i] - x[i]) ) for i in range(dimension)]
else:
new_v = [w * v[i] + c1 * random.uniform(0, ro_max) * (p[i] - x[i]) + c2 * random.uniform(0, ro_max) * (g[i] - x[i]) for i in range(dimension)]
return new_v
def main():
w = 1.0
w_best, w_worst = 1.25, 0.25
x_min = [minimum for i in range(dimension)]
x_max = [maximum for i in range(dimension)]
#粒子位置, 速度, パーソナルベスト, グローバルベストの初期化を行う
ps = [[random.randint(x_min[j], x_max[j]) for j in range(dimension)] for i in range(N)]
vs = [[0.0 for j in range(dimension)] for i in range(N)]
personal_best_positions = ps[:]
personal_best_scores = [criterion(p) for p in ps]
if max_or_min == 1:
best_particle = personal_best_scores.index(max(personal_best_scores))
elif max_or_min == 0:
best_particle = personal_best_scores.index(min(personal_best_scores))
global_best_position = personal_best_positions[best_particle][:]
for t in range(T):
for n in range(N):
x = ps[n][:]
v = vs[n][:]
p = personal_best_positions[n][:]
if option>=2:
best_list = sorted(personal_best_positions)
mu = bisect.bisect_left( best_list, p ) + 1
w = w_best - mu * (w_best - w_worst) / (N - 1)
#粒子の位置の更新を行う
new_x = update_position(x, v, x_min, x_max)
ps[n] = new_x[:]
#粒子の速度の更新を行う
new_v = update_velocity(new_x, v, p, global_best_position, w)
vs[n] = new_v[:]
#評価値を求め, パーソナルベストの更新を行う
score = criterion(new_x)
if max_or_min == 1:
if score > personal_best_scores[n]:
personal_best_scores[n] = score
personal_best_positions[n] = new_x[:]
elif max_or_min == 0:
if score < personal_best_scores[n]:
personal_best_scores[n] = score
personal_best_positions[n] = new_x[:]
#グローバルベストの更新を行う
if max_or_min == 1:
best_particle = personal_best_scores.index(max(personal_best_scores))
global_best_position = personal_best_positions[best_particle][:]
elif max_or_min == 0:
best_particle = personal_best_scores.index(min(personal_best_scores))
global_best_position = personal_best_positions[best_particle][:]
f.write(str(max(personal_best_scores))+"\n")
#最適解
if max_or_min == 1:
return max(personal_best_scores)
elif max_or_min == 0:
return min(personal_best_scores)
#--------------------------------------------------------------
with open('test_'+ str(option)+".txt", 'w') as f:
if max_or_min == 1:
best=-float("inf")
for i in range(iter):
best=max(best, main())
elif max_or_min == 0:
best=float("inf")
for i in range(iter):
best=min(best, main())
print(best)
|
import random
import bisect
import math
option = 0 # 0:PSO 1:CFA 2:CFArank
max_or_min = 0 # 0:minimize 1:maxmize
iter=2
N = 50 #粒子の数
T = 1000 #世代数(ループの回数)
maximum=1
minimum=0
dimension, limit = [int(i) for i in input().split()]
pi = [0 for i in range(dimension)]
ci = [0 for i in range(dimension)]
for i in range(dimension):
pi[i], ci[i] = [int(i) for i in input().split()]
tot = [pi[i] * (i+1) * 100 + ci[i] for i in range(dimension)]
#print(pi)
#print(ci)
#print(tot)
#--------粒 子 群 最 適 化------------------------------
#評価関数
def criterion(x):
z = sum([pi[i] * x[i] for i in range(dimension)])
z2 = sum([tot[i] * x[i] for i in range(dimension)])
k = -1
for i in range(dimension):
if x[dimension -1 -i] == 0:
k = dimension -1 -i
break
if k != -1:
for i in range(pi[k]):
if limit > z2:
z += 1
z2 += (k+1) * 100
else:
break
if limit > z2:
z = 10000
return z
#粒子の位置の更新を行う関数
def update_position(x, v, x_min, x_max):
# new_x = [x_min[i] if x[i]+ v[i] < x_min[i] else x_max[i] if x[i]+ v[i] > x_max[i] else x[i]+ v[i] for i in range(dimension)]
new_x = [1 if random.uniform(0, 1)< 1/(1+math.e**(-v[i])) else 0 for i in range(dimension)]
return new_x
#粒子の速度の更新を行う関数
def update_velocity(x, v, p, g, w, ro_max=1.0, c1=2.00, c2=0.75):
#パラメーターroはランダムに与える
phi=c1+c2
K=2/abs(2-phi-(phi*phi-4*phi)**0.5)
#粒子速度の更新を行う
if option!=0:
new_v = [K * ( w * v[i] + c1 * random.uniform(0, ro_max) * (p[i] - x[i]) + c2 * random.uniform(0, ro_max) * (g[i] - x[i]) ) for i in range(dimension)]
else:
new_v = [w * v[i] + c1 * random.uniform(0, ro_max) * (p[i] - x[i]) + c2 * random.uniform(0, ro_max) * (g[i] - x[i]) for i in range(dimension)]
return new_v
def main():
w = 1.0
w_best, w_worst = 1.25, 0.25
x_min = [minimum for i in range(dimension)]
x_max = [maximum for i in range(dimension)]
#粒子位置, 速度, パーソナルベスト, グローバルベストの初期化を行う
ps = [[random.randint(x_min[j], x_max[j]) for j in range(dimension)] for i in range(N)]
vs = [[0.0 for j in range(dimension)] for i in range(N)]
personal_best_positions = ps[:]
personal_best_scores = [criterion(p) for p in ps]
if max_or_min == 1:
best_particle = personal_best_scores.index(max(personal_best_scores))
elif max_or_min == 0:
best_particle = personal_best_scores.index(min(personal_best_scores))
global_best_position = personal_best_positions[best_particle][:]
for t in range(T):
for n in range(N):
x = ps[n][:]
v = vs[n][:]
p = personal_best_positions[n][:]
if option>=2:
best_list = sorted(personal_best_positions)
mu = bisect.bisect_left( best_list, p ) + 1
w = w_best - mu * (w_best - w_worst) / (N - 1)
#粒子の位置の更新を行う
new_x = update_position(x, v, x_min, x_max)
ps[n] = new_x[:]
#粒子の速度の更新を行う
new_v = update_velocity(new_x, v, p, global_best_position, w)
vs[n] = new_v[:]
#評価値を求め, パーソナルベストの更新を行う
score = criterion(new_x)
if max_or_min == 1:
if score > personal_best_scores[n]:
personal_best_scores[n] = score
personal_best_positions[n] = new_x[:]
elif max_or_min == 0:
if score < personal_best_scores[n]:
personal_best_scores[n] = score
personal_best_positions[n] = new_x[:]
#グローバルベストの更新を行う
if max_or_min == 1:
best_particle = personal_best_scores.index(max(personal_best_scores))
global_best_position = personal_best_positions[best_particle][:]
elif max_or_min == 0:
best_particle = personal_best_scores.index(min(personal_best_scores))
global_best_position = personal_best_positions[best_particle][:]
f.write(str(max(personal_best_scores))+"\n")
#最適解
if max_or_min == 1:
return max(personal_best_scores)
elif max_or_min == 0:
return min(personal_best_scores)
#--------------------------------------------------------------
with open('test_'+ str(option)+".txt", 'w') as f:
if max_or_min == 1:
best=-float("inf")
for i in range(iter):
best=max(best, main())
elif max_or_min == 0:
best=float("inf")
for i in range(iter):
best=min(best, main())
print(best)
|
p03290
|
d,g=list(map(int,input().split()))
data=[]
cp=[]
for i in range(1,d+1):
p,c=list(map(int,input().split()))
data.append(p)
cp.append(c)
a=99999999
for i in range(1024):
ct=0
ans=0
tmp=data[:]
for j in range(d):
if i&(1<<j):
ct+=100*(j+1)*data[j]+cp[j]
ans+=data[j]
tmp[j]=0
p=len(tmp)-1
while ct<g :
if tmp[p]>1:
ct+=100*(p+1)
tmp[p]-=1
ans+=1
else:
p-=1
if p<0:
ans=99999999
break
a=min(a,ans)
print(a)
|
d,g=list(map(int,input().split()))
data=[]
for i in range(d):
p,c=list(map(int,input().split()))
data.append((p,c))
n=0
mn=99999999
while n<2**d:
point=0
count=0
for i in range(d):
if n&(1<<i):
point+=data[i][0]*100*(i+1)+data[i][1]
count+=data[i][0]
if point<g:
for i in range(d):
i=d-1-i
if not n&(1<<i):
for j in range(data[i][0]-1):
point+=(i+1)*100
count+=1
if point>=g:
mn=min(mn,count)
break
else:
break
break
else:
mn=min(mn,count)
n+=1
print(mn)
|
p03290
|
D, G = [int(i) for i in input().split()]
pc = [list([int(x) for x in input().split()]) for i in range(D)]
pc.insert(0,[])
ans = float('inf')
def f(score, i, kaitousu):
global ans
if i <= D:
for j in range(pc[i][0] + 1):
if j == pc[i][0]:
newScore = score + 100 * i * j + pc[i][1]
else:
newScore = score + 100 * i * j
newKaitousu = kaitousu + j
if newScore >= G:
if newKaitousu < ans:
ans = newKaitousu
break
else:
f(newScore, i + 1, newKaitousu)
f(0, 1, 0)
print(ans)
|
D, G = list(map(int, input().split()))
P = [0]
C = [0]
ans = 0
for _ in range(D):
p, c = list(map(int, input().split()))
P.append(p)
C.append(c)
ans += p
for i in range(1<<D):
point = 0
count = 0
for j in range(D, 0, -1):
if i>>j-1&1:
point += j * 100 * P[j] + C[j]
count += P[j]
for k in range(D, 0, -1):
if not i>>k-1&1 and P[k] > 1:
for _ in range(P[k]-1):
if point < G:
point += k * 100
count += 1
else:
break
if point >= G:
ans = min(ans, count)
break
print(ans)
|
p03290
|
D,G=list(map(int,input().split()))
p=[0]*D
c=[0]*D
ans=1000000000
for i in range(D):
p[i],c[i]=list(map(int,input().split()))
for i in range(1<<D):
s=0
cnt=0
P=[0]*D
for j in range(D):
if ((i>>j)&1)==1:
s+=c[j]+(j+1)*p[j]*100
cnt+=p[j]
P[j]=1
while s<G:
for k in range(D):
if s>=G:
break
if P[D-k-1]==0:
for l in range(p[D-k-1]-1):
if s>=G:
break
else:
s+=(D-k)*100
cnt+=1
if cnt<ans:
ans=cnt
print(ans)
|
D,G=list(map(int,input().split()))
p=[0]*D
c=[0]*D
ans=1000000000
for i in range(D):
p[i],c[i]=list(map(int,input().split()))
for i in range(1<<D):
s=0
cnt=0
P=[0]*D
for j in range(D):
if ((i>>j)&1)==1:
s+=c[j]+(j+1)*p[j]*100
cnt+=p[j]
P[j]=1
m=-1
for k in range(D):
if m<0:
if P[D-k-1]==0:
m=D-k
else:
break
if m>=0:
for l in range(p[m-1]-1):
if s<G:
s+=m*100
cnt+=1
if s>=G and cnt<ans:
ans=cnt
print(ans)
|
p03290
|
import math
D,G = list(map(int,input().split()))
pc = [list(map(int,input().split()))for i in range(D)]
digit = "0"+str(D)+"b"
ans = float('INF')
for i in range(2**D):
pattern = list(str(format(i,digit)))
point = 0
count = 0
last0 = -1
for j in range(D):
if pattern[j] =="1":
point += pc[j][1]+pc[j][0]*100*(j+1)
count += pc[j][0]
else:
last0 = j
r = G - point
if r > 0 and last0 > -1:
tmp = math.ceil(r/(100*(last0+1)))
if tmp < pc[last0][0]:
count += tmp
ans = min(ans,count)
elif r <= 0:
ans = min(ans,count)
print(ans)
|
import math
D,G = list(map(int,input().split()))
pc = [list(map(int,input().split()))for _ in range(D)]
minimam=float('INF')
digit = "0"+str(D)+"b"
for i in range(2**D):
pattern = str(format(i,digit))
#この完答パターンのときの完答に伴う問題数と得点を算出する
point = 0
count = 0
for j in range(D):
if pattern[j]=="1":
count += pc[j][0]
point += pc[j][0]*100*(j+1)+pc[j][1]
#ポイントがGに未達の場合、残りの問題を解いてみて、Gに到達するか検証。
#到達する場合でなおかつ問題数が最小であれば記録する。
last0 = pattern.rfind("0")
r = G -point
if r > 0:
if last0==-1:
continue
tmp = math.ceil(r/(100*(last0+1)))
if tmp < pc[last0][0]:
minimam = min(minimam,tmp+count)
else:
minimam = min(minimam,count)
print(minimam)
|
p03290
|
import math
D,G = list(map(int,input().split()))
pc = [list(map(int,input().split()))for _ in range(D)]
digit = "0"+str(D)+"b"
ans = float("INF")
for i in range(2**D):
flags = list(str(format(i,digit)))
points = 0
problems = 0
last0 = -1
#まずは完答組での点数を算出
for j in range(D):
if int(flags[j]):
points += pc[j][0]*100*(j+1)+pc[j][1]
problems += pc[j][0]
else:
last0 = j
if points >= G:
ans = min(ans,problems)
continue
elif last0 == -1:
continue
else:
r = G-points
need = math.ceil(r/(100*(last0+1)))
if need > pc[last0][0]-1:
continue
else:
ans = min(ans,problems+need)
print(ans)
|
import math
D,G = list(map(int,input().split()))
pc = [list(map(int,input().split()))for _ in range(D)]
digit = "0"+str(D)+"b"
ans = float("INF")
for i in range(2**D):
flags = list(str(format(i,digit)))
points = 0
count = 0
last0 = -1
for j in range(D):
if flags[j]=="1":
points += pc[j][0]*100*(j+1) + pc[j][1]
count += pc[j][0]
else:
last0 = j
r = G - points
if r<=0:
ans = min(ans,count)
else:
if last0 == -1:
continue
need = math.ceil(r/(100*(last0+1)))
if need >= pc[last0][0]:
continue
else:
count += need
ans = min(ans,count)
print(ans)
|
p03290
|
import sys
sys.setrecursionlimit(10000)
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 pt >= G:
return depth
if depth >= probably_ans or index > D: # 遅いかも
return big
# 一つも引かない
probably_ans = min(probably_ans, hogehoge(depth, index + 1, pt, left, bonus, probably_ans))
# 全部引いて index reset
for k in range(0, D - index + 1):
if left[index + k]:
temp = left[index + k]
left[index + k] = 0
probably_ans = min(probably_ans, hogehoge(depth+temp, 1, pt + (index + k) * 100 * temp + bonus[index + k], left, bonus, probably_ans))
left[index + k] = temp
# 歯抜け状態から行けそうならクリア
if left[index]:
if pt + index * 100 * left[index] + bonus[index] >= G:
for i in range(1, left[index] + 1):
left[index] = left[index] - i
new_pt = pt + index * 100 * i + bonus[index] * (left[index] == 0)
if (new_pt >= G):
probably_ans = min(probably_ans, hogehoge(depth+i, index+1, new_pt, left, bonus, probably_ans))
left[index] = left[index] + i
return probably_ans
print((hogehoge(0, 1, 0, left, bonus, probably_ans)))
|
import sys
sys.setrecursionlimit(10000)
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
memo = {}
def hogehoge(depth, index, pt, left, bonus, probably_ans):
key = (depth, index, pt, str(left))
if key in memo:
return memo[key]
if pt >= G:
return depth
if depth >= probably_ans or index > D: # 遅いかも
return big
# 一つも引かない
probably_ans = min(probably_ans, hogehoge(depth, index + 1, pt, left, bonus, probably_ans))
# 全部引いて index reset
for k in range(0, D - index + 1):
if left[index + k]:
temp = left[index + k]
left[index + k] = 0
probably_ans = min(probably_ans, hogehoge(depth+temp, 1, pt + (index + k) * 100 * temp + bonus[index + k], left, bonus, probably_ans))
left[index + k] = temp
# 歯抜け状態から行けそうならクリア
if left[index]:
if pt + index * 100 * left[index] + bonus[index] >= G:
for i in range(1, left[index] + 1):
left[index] = left[index] - i
new_pt = pt + index * 100 * i + bonus[index] * (left[index] == 0)
if (new_pt >= G):
probably_ans = min(probably_ans, hogehoge(depth+i, index+1, new_pt, left, bonus, probably_ans))
left[index] = left[index] + i
memo[key] = probably_ans
return probably_ans
print((hogehoge(0, 1, 0, left, bonus, probably_ans)))
|
p03290
|
import itertools
D, G = list(map(int, input().split()))
score_list = []
for i in range(D):
p, c = list(map(int, input().split()))
score_list.append([(i + 1) * 100] * (p - 1) + [c + (i + 1) * 100])
full_score = [sum(i) for i in score_list]
per = list(itertools.permutations(list(range(D))))
ans = 10000
for k in per:
pro = 0
sco = 0
for i in k:
if G >= sco + full_score[i]:
sco += full_score[i]
pro += len(score_list[i])
else:
for j in score_list[i]:
sco += j
pro += 1
if sco >= G:
break
else:
continue
if sco >= G:
break
else:
continue
if ans > pro:
ans = pro
else:
continue
print(ans)
|
D, G = list(map(int, input().split()))
score_list = []
for i in range(D):
p, c = list(map(int, input().split()))
score_list.append([(i + 1) * 100] * (p - 1) + [c + (i + 1) * 100])
full_score = [sum(i) for i in score_list]
sol = [format(i, 'b').zfill(D) for i in range(2 ** D)]
ans = []
for i in sol:
problem = 0
score = 0
for j in range(D):
if i[j] == '1':
score += full_score[j]
problem += len(score_list[j])
else:
continue
if score >= G:
ans.append(problem)
else:
if score + full_score[i.rfind('0')] < G:
continue
else:
while score < G:
score += score_list[i.rfind('0')][0]
problem += 1
ans.append(problem)
print((min(ans)))
|
p03290
|
import heapq
n, need = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]
ret = float('inf')
for mask in range(1 << n):
total = 0
count = 0
pq = []
for bit in range(n):
num, bonus = a[bit]
points = (bit + 1) * 100
if (mask >> bit) & 1:
total += points * num + bonus
count += num
else:
for i in range(num):
heapq.heappush(pq, -points)
while total < need and pq:
total -= heapq.heappop(pq)
count += 1
if total >= need:
ret = min(ret, count)
print(ret)
|
n, need = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]
ret = float('inf')
for mask in range(1 << n):
total = 0
count = 0
for bit in range(n):
if (mask >> bit) & 1:
num, bonus = a[bit]
points = (bit + 1) * 100
total += points * num + bonus
count += num
for bit in range(n - 1, -1, -1):
if (mask >> bit) & 1 == 0:
num = a[bit][0]
points = (bit + 1) * 100
for i in range(num):
if total >= need:
break
total += points
count += 1
if total >= need:
ret = min(ret, count)
print(ret)
|
p03290
|
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
D, G, *PC = list(map(int, read().split()))
P = PC[::2]
C = PC[1::2]
ans = INF
for mask in range(1 << D):
problems = score = 0
available = [False] * D
for i in range(D):
if mask & (1 << i):
problems += P[i]
score += 100 * (i + 1) * P[i] + C[i]
else:
available[i] = True
if score >= G:
if ans > problems:
ans = problems
continue
for i in range(D - 1, -1, -1):
if not available[i]:
continue
if score + 100 * (i + 1) * P[i] + C[i] < G:
problems += P[i]
score += 100 * (i + 1) * P[i] + C[i]
else:
n = (G - score + 100 * (i + 1) - 1) // (100 * (i + 1))
problems += n
score += 100 * (i + 1) * n
break
if score >= G and ans > problems:
ans = problems
print(ans)
return
if __name__ == '__main__':
main()
|
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
D, G, *PC = list(map(int, read().split()))
P = PC[::2]
C = PC[1::2]
ans = INF
for mask in range(1 << D):
problems = score = 0
for i in range(D):
if mask & (1 << i):
problems += P[i]
score += 100 * (i + 1) * P[i] + C[i]
else:
idx_max = i
if score >= G:
if ans > problems:
ans = problems
continue
if score + 100 * (idx_max + 1) * (P[idx_max] - 1) >= G:
problems += (G - score + 100 * (idx_max + 1) - 1) // (100 * (idx_max + 1))
if ans > problems:
ans = problems
print(ans)
return
if __name__ == '__main__':
main()
|
p03290
|
from collections import deque
import itertools, math
d,g = list(map(int,input().split()))
pc = [list(map(int,input().split())) for _ in range(d)]
g /= 100
pat = list(itertools.permutations(list(range(d))))
ans = sum([pc[x][0] for x in range(d)])
def dfs(k, point, cnt, pat):
global ans
i = pat[k]
cnt += min(pc[i][0], math.ceil((g-point)/(i+1)))
point += min(pc[i][0], math.ceil((g-point)/(i+1))) * (i+1)
point += pc[i][1]//100
#print(k,i,point,cnt)
if point >= g:
ans = min(ans, cnt)
return
else:
if k < d-1:
dfs(k+1, point, cnt, pat)
for p in pat:
dfs(0, 0, 0, list(p))
print(ans)
|
from collections import deque
import itertools, math
d,g = list(map(int,input().split()))
pc = [list(map(int,input().split())) for _ in range(d)]
g /= 100
#ans = sum([pc[x][0] for x in range(d)])
ans = float('inf')
for bit in range(1<<d):
cnt = 0
point = 0
pat = set(range(1,d+1))
for i in range(d):
if bit & (1<<i):
point += pc[i][0]*(i+1) + pc[i][1]//100
cnt += pc[i][0]
pat.discard(i+1)
if point < g:
next = max(pat)
n = min(pc[next-1][0], math.ceil((g - point)/(next)))
cnt += n
point += n*(next)
if point >= g:
#print(ans,cnt)
ans = min(ans,cnt)
print(ans)
|
p03290
|
from collections import deque
import itertools, math
d,g = list(map(int,input().split()))
pc = [list(map(int,input().split())) for _ in range(d)]
g /= 100
#ans = sum([pc[x][0] for x in range(d)])
ans = float('inf')
for bit in range(1<<d):
cnt = 0
point = 0
pat = set(range(1,d+1))
for i in range(d):
if bit & (1<<i):
point += pc[i][0]*(i+1) + pc[i][1]//100
cnt += pc[i][0]
pat.discard(i+1)
if point < g:
next = max(pat)
n = min(pc[next-1][0], math.ceil((g - point)/(next)))
cnt += n
point += n*(next)
if point >= g:
#print(ans,cnt)
ans = min(ans,cnt)
print(ans)
|
d,g = list(map(int,input().split()))
pc = [list(map(int,input().split())) for _ in range(d)]
ans = float('inf')
for bit in range(1<<d):
sum = 0
cnt = 0
rem = set(range(d))
for i in range(d):
if bit & 1<<i:
sum += pc[i][0]*(i+1)*100 + pc[i][1]
cnt += pc[i][0]
rem.discard(i)
if sum < g:
u = max(rem)
n = min(pc[u][0], -( -(g-sum)//((u+1)*100) ))
cnt += n
sum += n*(u+1)*100
if sum >= g:
ans = min(ans, cnt)
print(ans)
|
p03290
|
from math import ceil
D, G = [int(t) for t in input().split()]
p = []
c = []
for i in range(D):
p_, c_ = [int(t) for t in input().split()]
p.append(p_)
c.append(c_)
def solve(G, i):
"""100i点以下の問題だけでGを達成する最小問題数"""
if i <= 0:
return float('inf')
#最も配転が高い問題で総合点を超えることができるか確認
n = min(ceil(G / (100 * i)), p[i - 1])
s = 100 * i * n
#もし総合展を超えることができるときの問題数がボーナス点に達するならば足す
if n == p[i - 1]:
s += c[i - 1]
if G > s:
n += solve(G - s, i - 1)
return min(n, solve(G, i - 1))
print((solve(G, D)))
|
from math import ceil
D,G = list(map(int,input().split()))
list = [list(map(int,input().split())) for _ in range(D)]
def dfs(G,i):
if i <= 0:
return float('inf')
n = min(ceil(G/(100*i)),list[i-1][0])
s = 100*i*n
if n == list[i-1][0]:
s += list[i-1][1]
if G > s:
n += dfs(G-s,i-1)
return min(n,dfs(G,i-1))
print((dfs(G,D)))
|
p03290
|
d, g = list(map(int, input().split()))
pc = [0] + [[int(i) for i in input().split()] for i in range(d)]
def dfs(g, i):
if i == 0:
return 10 ** 12
n = min(g // (100 * i), pc[i][0])
score = n * 100 * i
if n == pc[i][0]:
score += pc[i][1]
if g > score:
n += dfs(g - score, i - 1)
return min(n, dfs(g, i - 1))
print((dfs(g, d)))
|
d, g = list(map(int, input().split()))
PC = [0] + [[int(i) for i in input().split()] for i in range(d)]
def dfs(g, i):
if i == 0:
return 10 ** 12
n = min(g // (100 * i), PC[i][0])
score = n * 100 * i
if n == PC[i][0]:
score += PC[i][1]
if g > score:
n += dfs(g - score, i - 1)
return min(n, dfs(g, i - 1))
print((dfs(g, d)))
|
p03290
|
D , G = list(map(int,input().split()))
questions = []
for i in range(D):
p , c = list(map(int,input().split()))
questions.append([p,c])
ans = float("inf")
for bit in range(2 ** D):
tmp_ans = 0
tmp_sum = 0
for j in range(D):
if bit >> j & 1:
tmp_sum += questions[j][0] * 100 * (j + 1) + questions[j][1]
tmp_ans += questions[j][0]
if tmp_sum < G:
for j in range(D - 1 , -1 , -1):
if bit >> j & 1:
continue
else:
for k in range(questions[j][0]):
tmp_ans += 1
tmp_sum += 100 * (j + 1)
if tmp_sum >= G:
break
if tmp_sum >= G:
break
if tmp_ans < ans and tmp_sum >= G:
ans = tmp_ans
print(ans)
|
D , G = list(map(int,input().split()))
bonus = []
question_cnt = []
for i in range(D):
p , c = list(map(int,input().split()))
question_cnt.append(p)
bonus.append(c)
ans = float('inf')
for bit in range(2 ** D):
sum_val = 0
tmp_ans = 0
Flag = False
for j in range(D):
if bit >> j & 1:
sum_val += question_cnt[j] * (j + 1) * 100 + bonus[j]
tmp_ans += question_cnt[j]
if sum_val < G:
for j in range(D-1 , - 1 , -1):
if Flag:
break
if not bit >> j & 1:
Flag = True
for k in range(question_cnt[j]):
sum_val += (j + 1) * 100
tmp_ans += 1
if sum_val >= G:
break
if tmp_ans < ans and sum_val >= G:
ans = tmp_ans
print(ans)
|
p03290
|
import math
D, G = list(map(int, input().split()))
lst = [list(map(int, input().split())) for _ in range(D)]
ret = 1000 ** 10
for i in range(2 ** D):
total = 0
cnt = 0
digit = 1
for p in range(D):
if (digit << p) & i:
cnt += lst[p][0]
total += lst[p][0] * (p + 1) * 100 + lst[p][1]
for p in range(D)[::-1]:
if not ((digit << p) & i):
delta = max(0, G - total)
n = min(math.ceil(delta / ((p + 1) * 100)), lst[p][0])
cnt += n
total += n * (p + 1) * 100
ret = min(ret, cnt)
print(ret)
|
import math
D, G = list(map(int, input().split()))
lst = [list(map(int, input().split())) for _ in range(D)]
ret = 1000 ** 10
for i in range(2 ** D):
total = 0
cnt = 0
for p in range(D):
if (i >> p) & 1:
cnt += lst[p][0]
total += lst[p][0] * (p + 1) * 100 + lst[p][1]
for p in range(D)[::-1]:
delta = G - total
if delta <= 0:
break
if not ((i >> p) & 1):
n = min(math.ceil(delta / ((p + 1) * 100)), lst[p][0])
cnt += n
total += n * (p + 1) * 100
ret = min(ret, cnt)
print(ret)
|
p03290
|
d,g=list(map(int,input().split()))
g=g//100
pc=[list(map(int,input().split())) for i in range(d)]
P=0
C=0#合計
for i in range(d):
pc[i][1]=pc[i][1]//100
C=(C+pc[i][1]+pc[i][0]*(i+1))
P+=pc[i][0]
dp=[10000000]*(C+1)
for i in range(d):
dp_sub=[10000000]*(C+1)
for j in range(C+1):
if j==0:
for k in range(1,pc[i][0]+1):
if k!=pc[i][0]:
dp_sub[k*(i+1)]=k
else:
dp_sub[k*(i+1)+pc[i][1]]=k
elif dp[j]!=10000000:
for k in range(1,pc[i][0]+1):
if k!=pc[i][0]:
dp_sub[j+k*(i+1)]=min(dp[j]+k,dp_sub[j+k*(i+1)])
else:
dp_sub[j+k*(i+1)+pc[i][1]]=min(dp[j]+k,dp_sub[j+k*(i+1)+pc[i][1]])
for j in range(C+1):
if dp_sub[j]!=0:
dp[j]=min(dp[j],dp_sub[j])
m=P
for i in range(g,C+1):
if dp[i]!=0:
m=min(m,dp[i])
print(m)
|
import math
d,g=list(map(int,input().split()))
pc=[list(map(int,input().split())) for i in range(d)]
ans=10000000000000000000
for i in range(1<<d):
s=0
ans_=0
for j in range(d):
if (i>>j)&1:
s+=(pc[j][1]+pc[j][0]*100*(j+1))
ans_+=pc[j][0]
#print(s,ans_)
if s>=g:
ans=min(ans,ans_)
else:
for j in range(d-1,-1,-1):
if not((i>>j)&1):
if s+(pc[j][0]*100*(j+1))>=g:
h=-((s-g)//(100*(j+1)))
s+=(h*100*(j+1))
ans_+=h
ans=min(ans,ans_)
break
else:
break
print(ans)
#ansとans_
#謎のWA
|
p03290
|
D,G = list(map(int,input().split()))
PC = []
L = []
t = 10 ** 9
m = 0
for i in range(1,D + 1):
p,c = list(map(int,input().split()))
s = 0
pc = []
for j in range(p):
s += i * 100
if j == p - 1:
s += c
L.append([j + 1,s])
if s >= G and j + 1 < t:
t = j + 1
pc.append([j + 1,s])
PC.append(pc)
def recur(problems):
#探索の終了
if len(problems) == D:
ans = 10 ** 9
score = 0
times = 0
#全部使用した問題セットの合計点と回答数を記録
for j in range(D):
if problems[j] == 1:
score += L[j][1]
times += L[j][0]
#全問全回答の例を除く
if score >= G:
ans = min(ans,times)
return ans
#残りの数以上となる回答数のうち最小のものが見つかれば更新し
#全回答の回答数に足す
else:
remain = G - score
if remain <= max([L[i][1] for i in range(D) if problems[i] == 0]):
for k in range(D):
if problems[k] == 0:
for l in range(len(PC[k])):
if remain <= PC[k][l][1] and ans >= PC[k][l][0]:
ans = PC[k][l][0]
ans += times
return ans
else:
return 10 ** 9
else:
#問題セットを全部使う
ret1 = recur(problems + [1])
#使わない
ret2 = recur(problems + [0])
return min(ret1,ret2)
print((recur([])))
|
import math
D, G = list(map(int, input().split()))
PC = []
for _ in range(D):
p, c = list(map(int, input().split()))
PC.append([p, c])
ans = 10 ** 9
#全部解く・解かないが2のD乗通りになる
for i in range(2 ** D):
score = 0
time = 0
maxj = -1
#全部解く場合
for j in range(D):
#jケタ落としていき、jケタめ == 1であれば、つまりj番目の問題セットを全部解いていれば
if ((i >> j) & 1):
score += (j + 1) * PC[j][0] * 100 + PC[j][1]
time += PC[j][0]
#全てを解かなかった問題セットのうち最も大きいj
##全て解かない問題セットは1つでよく、最大の素点のもの=一番大きいjでよい
else:
maxj = max(maxj,j)
#全てを全部解いた場合
if maxj == -1:
ans = min(ans, time)
#jケタめを全て使わずにG以上のスコアとなった場合
elif score + (maxj + 1) * (PC[maxj][0] - 1) * 100 >= G:
#必要な最小問題数を小数点切り上げで求める
##残りが500点であったとき、300点問題なら2問、200点問題なら3問解けばよい
time += max(0, math.ceil((G - score) / (maxj + 1) / 100))
#最小のものを更新していく
ans = min(ans, time)
print(ans)
|
p03290
|
from itertools import *
from math import *
D, G = list(map(int, input().split()))
probs = [list(map(int, input().split())) for _ in range(D)]
seq = list(range(D))
x = list(permutations(seq, D))
#print(x)
ans = float("inf")
G2=G
for i in range(len(x)):
cand = x[i]
cnt = 0
G=G2
for j in range(D):
ind = cand[j]
probpoint = (ind + 1) * 100
if G<=0:
break
if G <= probpoint * (probs[ind][0] - 1):
cnt = cnt + ceil(G / probpoint)
G=G-probpoint*ceil(G / probpoint)
else:
cnt=cnt+probs[ind][0]
G=G-(probpoint * probs[ind][0]+probs[ind][1])
ans=min(ans,cnt)
print(ans)
|
from itertools import *
from math import *
D, G = list(map(int, input().split()))
probs = [list(map(int, input().split())) for _ in range(D)]
seq = list(range(D))
x = list(permutations(seq, D))
#print(x)
ans = float("inf")
G2=G
for cand in x:
cnt = 0
G=G2
for ind in cand:
probpoint = (ind + 1) * 100
if G<=0:
break
if G <= probpoint * (probs[ind][0] - 1):
cnt = cnt + ceil(G / probpoint)
G=G-probpoint*ceil(G / probpoint)
else:
cnt=cnt+probs[ind][0]
G=G-(probpoint * probs[ind][0]+probs[ind][1])
ans=min(ans,cnt)
print(ans)
|
p03290
|
from itertools import accumulate
from operator import add
N, K = list(map(int, input().split()))
K2 = 2 * K
# Gss[i][j]: 「市松模様の黒い部分の右上のマス」が(i,j)のとき、満たせる要望の個数
Gss = [[0] * K2 for i in range(K2)]
for i in range(N):
x, y, c = input().split()
x, y = int(x), int(y)
# 要望を「0<=x<2K, 0<=y<K, 'B'」に変換する
if c == 'W':
x -= K
x, y = x % K2, y % K2
if y >= K:
x, y = (x - K) % K2, y - K
# 要望を満たす「市松模様の黒い部分の右上のマス」に対して、+1する
# (後で累積和を取る)
Gss[x][y] += 1
Gss[x][y - K] += -1
if x != K:
Gss[x - K][y - K] += 1
Gss[x - K][y] += -1
if x > K:
Gss[0][y] += 1
Gss[0][y - K] += -1
# 累積和を取る
Gss = [list(accumulate(Gs)) for Gs in Gss]
Gss = [list(accumulate(Gs)) for Gs in zip(*Gss)]
Gss = list(map(list, list(zip(*Gss)))) # 転置
# 「K<=y<2K」の部分を、「0<=y<K」に重ね合わせる
Gss = [list(map(add, Gss[i][:K], Gss[i - K][K:])) for i in range(K2)]
# Gssの最大値が答え
print((max(list(map(max, Gss)))))
|
from itertools import accumulate
from operator import add
N, K = list(map(int, input().split()))
K2 = 2 * K
# Gss[i][j]: 「市松模様の黒い部分の右上のマス」が(i,j)のとき、満たせる要望の個数
Gss = [[0] * K2 for i in range(K2)]
for i in range(N):
x, y, c = input().split()
x, y = int(x), int(y)
# 要望を「0<=x<2K, 0<=y<K, 'B'」に変換する
if c == 'W':
x -= K
x, y = x % K2, y % K2
if y >= K:
x, y = (x - K) % K2, y - K
# 要望を満たす「市松模様の黒い部分の右上のマス」に対して、+1する
# (後で累積和を取る)
Gss[x][y] += 1
Gss[x][y - K] += -1
if x != K:
Gss[x - K][y - K] += 1
Gss[x - K][y] += -1
if x > K:
Gss[0][y] += 1
Gss[0][y - K] += -1
# 累積和を取る
Gss = [accumulate(Gs) for Gs in Gss]
Gss = [accumulate(Gs) for Gs in zip(*Gss)]
Gss = list(map(list, list(zip(*Gss)))) # 転置
# 「K<=y<2K」の部分を、「0<=y<K」に重ね合わせる
Gss = [list(map(add, Gss[i][:K], Gss[i - K][K:])) for i in range(K2)]
# Gssの最大値が答え
print((max(list(map(max, Gss)))))
|
p03460
|
from collections import defaultdict
n, k = list(map(int, input().split()))
k2 = k * 2
requires = defaultdict(lambda: [0, 0])
for i in range(n):
x, y, c = input().split()
x, y = int(x), int(y)
rx, ry = x % k2, y % k2
b = c == 'B'
if rx > k:
if ry > k:
rx -= k
ry -= k
else:
rx -= k
b = not b
requires[rx, ry][b] += 1
ans = 0
for dx in range(k):
for dy in range(k):
cnt_w, cnt_b = 0, 0
for (x, y), (w, b) in list(requires.items()):
f = ((x + dx) // k + (y + dy) // k) & 1
if f:
cnt_w += b
cnt_b += w
else:
cnt_w += w
cnt_b += b
ans = max(ans, cnt_b, cnt_w)
print(ans)
|
from itertools import accumulate
n, k = list(map(int, input().split()))
k2 = k * 2
req_b = [[0] * k for _ in range(k)]
req_w = [[0] * k for _ in range(k)]
bc, wc = 0, 0
for i in range(n):
x, y, c = input().split()
x, y = int(x), int(y)
rx, ry = x % k2, y % k2
b = c == 'B'
if rx >= k:
rx -= k
if ry >= k:
ry -= k
else:
b = not b
elif ry >= k:
ry -= k
b = not b
if b:
req_b[rx][ry] += 1
bc += 1
else:
req_w[rx][ry] += 1
wc += 1
req_b[0] = list(accumulate(req_b[0]))
req_w[0] = list(accumulate(req_w[0]))
for i in range(1, k):
req_b[i][0] += req_b[i - 1][0]
req_w[i][0] += req_w[i - 1][0]
for j in range(1, k):
req_b[i][j] += req_b[i][j - 1] + req_b[i - 1][j] - req_b[i - 1][j - 1]
req_w[i][j] += req_w[i][j - 1] + req_w[i - 1][j] - req_w[i - 1][j - 1]
ans = 0
for dx in range(k):
dxk_b = req_b[dx][-1]
dxk_w = req_w[dx][-1]
for dy in range(k):
b1 = req_b[dx][dy]
b2 = bc - req_b[k - 1][dy] - dxk_b + b1
w1 = req_w[dx][dy]
w2 = wc - req_w[k - 1][dy] - dxk_w + w1
b, w = b1 + b2, w1 + w2
ans = max(ans, b + wc - w, w + bc - b)
# print(dx, dy, b, w, b + wc - w, w + bc - b)
print(ans)
|
p03460
|
from itertools import accumulate
n, k = list(map(int, input().split()))
k2 = k * 2
req_b = [[0] * k for _ in range(k)]
req_w = [[0] * k for _ in range(k)]
bc, wc = 0, 0
for i in range(n):
x, y, c = input().split()
x, y = int(x), int(y)
rx, ry = x % k2, y % k2
b = c == 'B'
if rx >= k:
rx -= k
if ry >= k:
ry -= k
else:
b = not b
elif ry >= k:
ry -= k
b = not b
if b:
req_b[rx][ry] += 1
bc += 1
else:
req_w[rx][ry] += 1
wc += 1
req_b[0] = list(accumulate(req_b[0]))
req_w[0] = list(accumulate(req_w[0]))
for i in range(1, k):
req_b[i][0] += req_b[i - 1][0]
req_w[i][0] += req_w[i - 1][0]
for j in range(1, k):
req_b[i][j] += req_b[i][j - 1] + req_b[i - 1][j] - req_b[i - 1][j - 1]
req_w[i][j] += req_w[i][j - 1] + req_w[i - 1][j] - req_w[i - 1][j - 1]
ans = 0
for dx in range(k):
dxk_b = req_b[dx][-1]
dxk_w = req_w[dx][-1]
for dy in range(k):
b1 = req_b[dx][dy]
b2 = bc - req_b[k - 1][dy] - dxk_b + b1
w1 = req_w[dx][dy]
w2 = wc - req_w[k - 1][dy] - dxk_w + w1
b, w = b1 + b2, w1 + w2
ans = max(ans, b + wc - w, w + bc - b)
# print(dx, dy, b, w, b + wc - w, w + bc - b)
print(ans)
|
from itertools import accumulate
n, k = list(map(int, input().split()))
k2 = k * 2
req_b = [[0] * k for _ in range(k)]
req_w = [[0] * k for _ in range(k)]
bc, wc = 0, 0
for i in range(n):
x, y, c = input().split()
x, y = int(x), int(y)
rx, ry = x % k2, y % k2
b = c == 'B'
if rx >= k:
rx -= k
if ry >= k:
ry -= k
else:
b = not b
elif ry >= k:
ry -= k
b = not b
if b:
req_b[rx][ry] += 1
bc += 1
else:
req_w[rx][ry] += 1
wc += 1
req_b = [list(accumulate(req)) for req in req_b]
req_w = [list(accumulate(req)) for req in req_w]
req_b = [list(accumulate(req)) for req in zip(*req_b)]
req_w = [list(accumulate(req)) for req in zip(*req_w)]
ans = 0
kb, kw = req_b[-1], req_w[-1]
for dx, (dx_b, dx_w) in enumerate(zip(req_b, req_w)):
dxk_b = dx_b[-1]
dxk_w = dx_w[-1]
for b1, w1, kyb, kyw in zip(dx_b, dx_w, kb, kw):
b = bc - kyb - dxk_b + b1 * 2
w = wc - kyw - dxk_w + w1 * 2
a = b + wc - w
ans = max(ans, a, n - a)
print(ans)
|
p03460
|
N, K = list(map(int, input().split()))
dK = 2*K
MeetDemand =[[0 for c in range(dK+1)] for r in range(dK)]
for i in range(N):
x, y, c =input().split()
x = int(x) % dK
y = (int(y)+K if c=="W" else int(y)) % dK
if 0 <= x < K and 0 <= y < K:
MeetDemand[0][0] += 1
MeetDemand[x+1][y+1] += 2
MeetDemand[0][y+1] -= 1
MeetDemand[x+1][0] -= 1
MeetDemand[0][y+K+1] += 1
MeetDemand[x+1][y+K+1] -= 2
elif 0 <= x < K:
MeetDemand[0][y-K+1] += 1
MeetDemand[x+1][y-K+1] -= 2
MeetDemand[x+1][0] += 1
MeetDemand[0][y+1] -= 1
MeetDemand[x+1][y+1] += 2
elif 0 <= y < K:
MeetDemand[x-K+1][0] += 1
MeetDemand[x-K+1][y+1] -= 2
MeetDemand[0][y+1] += 1
MeetDemand[0][y+K+1] -= 1
MeetDemand[x-K+1][y+K+1] += 2
else:
MeetDemand[0][0] += 1
MeetDemand[0][y-K+1] -= 1
MeetDemand[x-K+1][0] -= 1
MeetDemand[x-K+1][y-K+1] += 2
MeetDemand[0][y+1] += 1
MeetDemand[x-K+1][y+1] -= 2
for x in range(K):
for y in range(1, dK):
MeetDemand[x][y] += MeetDemand[x][y-1]
for y in range(dK):
for x in range(1, K):
MeetDemand[x][y] += MeetDemand[x-1][y]
Ans = max(MeetDemand[0][:dK])
for i in range(1, K):
Ans = max(Ans, max(MeetDemand[i][:dK]))
print(Ans)
|
N, K = list(map(int, input().split()))
dK = 2*K
MeetDemand =[[0 for y in range(dK+1)] for x in range(K+1)]
for i in range(N):
x, y, c =input().split()
x = int(x) % dK
y = (int(y)+K if c=="W" else int(y)) % dK
if K <= x:
if 0 <= y < K:
x -= K
y += K
else:
x %= K
y %= K
if 0 <= y < K:
MeetDemand[0][0] += 1
MeetDemand[x+1][y+1] += 2
MeetDemand[0][y+1] -= 1
MeetDemand[x+1][0] -= 1
MeetDemand[0][y+K+1] += 1
MeetDemand[x+1][y+K+1] -= 2
else:
MeetDemand[0][y-K+1] += 1
MeetDemand[x+1][y-K+1] -= 2
MeetDemand[x+1][0] += 1
MeetDemand[0][y+1] -= 1
MeetDemand[x+1][y+1] += 2
for x in range(K):
for y in range(1, dK):
MeetDemand[x][y] += MeetDemand[x][y-1]
for y in range(dK):
for x in range(1, K):
MeetDemand[x][y] += MeetDemand[x-1][y]
Ans = max(MeetDemand[0][:dK])
for i in range(1, K):
Ans = max(Ans, max(MeetDemand[i][:dK]))
print(Ans)
|
p03460
|
def get(i1, j1, i2, j2):
if i1 > i2 or j1 > j2 or i1 < 0 or j1 < 0 or i2 < 0 or j2 < 0:
return 0
elif i1 > 0 and j1 > 0:
return l[i2][j2] - l[i1-1][j2] - l[i2][j1-1] + l[i1-1][j1-1]
elif i1 <= 0 < j1:
return l[i2][j2] - l[i2][j1-1]
elif j1 <= 0 < i1:
return l[i2][j2] - l[i1 - 1][j2]
else:
return l[i2][j2]
N, K = list(map(int, input().split()))
K2 = 2*K
R = []
l=[[0] * K2 for _ in range(K2)]
for i in range(N):
xi, yi, ci = input().split()
if ci == "W":
yi = int(yi) + K
xi, yi = int(xi), int(yi)
l[xi%K2][yi%K2]+=1
for y in range(K2):
for x in range(1,K2):
l[x][y] += l[x-1][y]
for y in range(1,K2):
for x in range(K2):
l[x][y] += l[x][y-1]
ans = 0
for i in range(K):
for j in range(K):
tmp = 0
tmp += get(0, 0, i-1, j-1)
tmp += get(0, j+K, i-1, K2-1)
tmp += get(i+K, j+K, K2-1, K2-1)
tmp += get(i+K, 0, K2-1, j-1)
tmp += get(i, j, i+K-1, j+K-1)
ans = max(ans, tmp, N-tmp)
print(ans)
|
def cl(i1,j1,i2,j2):
if i1>i2 or j1>j2 or i1<0 or j1<0 or i2<0 or j2<0:
return 0
v=l[i2][j2]
if i1>0:
v-=l[i1-1][j2]
if j1>0:
v-=l[i2][j1-1]
if i1>0 and j1>0:
v+=l[i1-1][j1-1]
return v
N,K=list(map(int,input().split()))
K2=2*K
l=[[0]*K2 for _ in range(K2)]
for i in range(N):
xi,yi,ci=input().split()
xi,yi=int(xi),int(yi)
if ci=="W":yi+=K
l[xi%K2][yi%K2]+=1
for y in range(K2):
for x in range(1,K2):
l[x][y]+=l[x-1][y]
for y in range(1,K2):
for x in range(K2):
l[x][y]+=l[x][y-1]
ans=0
for i in range(K):
for j in range(K):
tmp=0
tmp+=cl(0,0,i-1,j-1)
tmp+=cl(0,j+K,i-1,K2-1)
tmp+=cl(i+K,j+K,K2-1,K2-1)
tmp+=cl(i+K,0,K2-1,j-1)
tmp+=cl(i,j,i+K-1,j+K-1)
ans = max(ans,tmp,N-tmp)
print(ans)
|
p03460
|
from collections import defaultdict
def calc(K, xyc):
K2 = K * 2
N = len(xyc)
m = defaultdict(int)
for x, y, c in xyc:
y += c * K
x1, y1 = x % K2, y % K2
x2, y2 = x1 + K, y1 + K
m[x1, y1] += 1
m[x2, y2] += 1
m[x2, y1] -= 1
m[x1, y2] -= 1
x1, y1 = (x + K) % K2, (y + K) % K2
x2, y2 = x1 + K, y1 + K
m[x1, y1] += 1
m[x2, y2] += 1
m[x2, y1] -= 1
m[x1, y2] -= 1
ms = [[0] * (K2 + 1) for i in range(K2 + 1)]
for y in range(0, K2):
ms0 = ms[y]
ms1 = ms[y - 1]
for x in range(0, K2):
ms0[x] = m[x, y] + ms0[x-1] + ms1[x] - ms1[x-1]
rmax = 0
for y in range(K, K2):
for x in range(K, K2):
rcount = ms[y][x]
rmax = max(rmax, rcount, N - rcount)
return rmax
if __name__ == '__main__':
N, K = [int(e) for e in input().split()]
xyc = [(int(x), int(y), c == "W") for x, y, c in [input().split() for i in range(N)]]
print((calc(K, xyc)))
|
def calc(K, xyc):
K2 = K * 2
N = len(xyc)
p = [[0] * K2 for i in range(K2)]
for x, y, c in xyc:
y += c * K
p[x % K2][y % K2] += 1
p[(x + K) % K2][(y + K) % K2] += 1
def isum(xs):
r = 0
yield r
for x in xs:
r += x
yield r
psum = [list(isum(row)) for row in p]
pksum = [[b - a for a, b in zip(row, row[K:])] for row in psum]
rmax = N / 2
for y in range(K):
rcount = sum(row[y] for row in pksum[:K])
for x in range(K):
rmax = max(rmax, rcount, N - rcount)
rcount += -pksum[x][y] + pksum[x + K][y]
return rmax
if __name__ == '__main__':
N, K = [int(e) for e in input().split()]
xyc = [(int(x), int(y), c == "W") for x, y, c in [input().split() for i in range(N)]]
print((calc(K, xyc)))
|
p03460
|
def calc(K, xyc):
K2 = K * 2
N = len(xyc)
p = [[0] * K2 for i in range(K2)]
for x, y, c in xyc:
y += c * K
p[x % K2][y % K2] += 1
p[(x + K) % K2][(y + K) % K2] += 1
def isum(xs):
r = 0
yield r
for x in xs:
r += x
yield r
psum = [list(isum(row)) for row in p]
pksum = [[b - a for a, b in zip(row, row[K:])] for row in psum]
rmax = N / 2
for y in range(K):
rcount = sum(row[y] for row in pksum[:K])
for x in range(K):
rmax = max(rmax, rcount, N - rcount)
rcount += -pksum[x][y] + pksum[x + K][y]
return rmax
if __name__ == '__main__':
N, K = [int(e) for e in input().split()]
xyc = [(int(x), int(y), c == "W") for x, y, c in [input().split() for i in range(N)]]
print((calc(K, xyc)))
|
def calc(K, xyc):
K2 = K * 2
N = len(xyc)
p = [[0] * K2 for i in range(K2)]
for x, y, c in xyc:
y += c * K
p[x % K2][y % K2] += 1
p[(x + K) % K2][(y + K) % K2] += 1
def calcsum(xs):
r = sum(xs[:K])
yield r
for a, b in zip(xs[:K], xs[K:]):
r += -a + b
yield r
pksum = [list(calcsum(xs)) for xs in p]
rmax = N / 2
for y in range(K):
rcount = sum(row[y] for row in pksum[:K])
for x in range(K):
rmax = max(rmax, rcount, N - rcount)
rcount += -pksum[x][y] + pksum[x + K][y]
return rmax
if __name__ == '__main__':
N, K = [int(e) for e in input().split()]
xyc = [(int(x), int(y), c == "W") for x, y, c in [input().split() for i in range(N)]]
print((calc(K, xyc)))
|
p03460
|
import functools
import operator
print(('Even' if (functools.reduce(operator.mul,list(map(int,input().split()))))%2==0 else 'Odd'))
|
print(('Odd' if len([1 for i in list(map(int,input().split())) if i%2!=0])==2 else 'Even'))
|
p03455
|
a,b=input().split();print(('EOvdedn'[eval(a+'*'+b)%2!=0::2]))
|
print(('EOvdedn'[eval(input().replace(' ','*'))%2!=0::2]))
|
p03455
|
print(('EOvdedn'[eval(input().replace(' ','*'))%2::2]))
|
a,b=list(map(int,input().split()));print(('EOvdedn'[a%2 and b%2::2]))
|
p03455
|
lis = []
lis = input().split()
answer = 1
for lis_value in lis:
answer *= int(lis_value)
print(("Even" if answer % 2 == 0 else "Odd"))
|
a,b = list(map(int,input().split()))
if a*b % 2 == 0:
print("Even")
else:
print("Odd")
|
p03455
|
a, b = list(map(int, input().split()))
print(('Odd' if a & 1 and b & 1 else 'Even'))
|
a, b = list(map(int, input().split()))
print(('Odd' if a*b % 2 == 1 else 'Even'))
|
p03455
|
import operator
import functools
number_list = list(map(int, input().split()))
product = functools.reduce(operator.mul, number_list)
if product % 2 == 0:
print('Even')
else:
print('Odd')
|
a, b = list(map(int, input().split()))
if (a * b % 2) == 0:
print('Even')
else:
print('Odd')
|
p03455
|
a,b = list(map(int, input().split()))
print(("Even" if (a * b) % 2 == 0 else "Odd"))
|
a,b = list(map(int, input().split()))
if (a * b) % 2 == 0:
print("Even")
else:
print("Odd")
|
p03455
|
a, b = input().split(' ')
multi_a_b = int(a) * int(b)
if multi_a_b % 2 == 0:
print('Even')
else:
print('Odd')
|
a, b = list(map(int, input().split()))
if (a * b) % 2 == 0:
print('Even')
else:
print('Odd')
|
p03455
|
a,b=list(map(int,input().split()))
v=a*b
print(("Even" if v%2==0 else "Odd"))
|
a,b=map(int,input().split())
print("Even") if a*b%2==0 else print("Odd")
|
p03455
|
(a, b) = list(map(int, input().split()))
if a % 2 == 1 and b % 2 == 1:
print("Odd")
else:
print("Even")
|
a, b = list(map(int, input().split()))
if a % 2 == 1 and b % 2 == 1:
print("Odd")
else:
print("Even")
|
p03455
|
a, b = list(map(int, input().split()))
if a*b % 2 == 0:
print("Even")
else:
print("Odd")
|
a, b=list(map(int, input().split()))
s="Odd" if a%2!=0 and b%2!=0 else "Even"
print(s)
|
p03455
|
a,b=list(map(int,input().split()))
print(('Odd'if a*b%2==1else'Even'))
|
a,b=list(map(int,input().split()));print((['Even','Odd'][a*b%2]))
|
p03455
|
a, b =list(map(int, input().split()))
product = a * b
if product % 2 == 0:
print("Even")
else:
print("Odd")
|
a, b = list(map(int, input().split()))
pro = a * b
if pro % 2 == 0:
print("Even")
else:
print("Odd")
|
p03455
|
a,b = list(map(int, input().split()))
print(("Odd" if a*b%2!=0 else "Even"))
|
a, b = list(map(int, input().split()))
if a * b % 2 == 0:
print('Even')
else:
print('Odd')
|
p03455
|
# -*- codinf: utf-8 -*-
# コマンドラインの入力文字をリストに格納
# input().split() -> 入力文字を空白区切りで取得 ※inputは文字列として取得する。split()でリスト型に変換
# for num in input().split() -> 取得した入力文字を一つずつnum変数に格納
# int(num)で格納されたnum変数を数値に変換
numList = [int(num) for num in input().split()]
# 入力文字の乗算
productNumList = numList[0] * numList[1]
# 奇数/偶数の判定
if ((productNumList % 2) == 0 ):
print("Even")
else:
print("Odd")
|
#2019/10/10
a, b = list(map(int, open(0).read().split()))
print(("Odd" if (a*b)%2!=0 else "Even"))
|
p03455
|
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
INF = 10**18
a,b=rl()
print('Odd' if a*b%2==1 else 'Even')
|
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18
a,b=rl()
#print('Odd' if a*b%2==1 else 'Even')
OE(a*b)
|
p03455
|
a,b = list(map(int,input().split()))
num = a * b
mod = num % 2
if mod == 0:
print("Even")
else:
print("Odd")
|
a,b = list(map(int,input().split()))
if a*b%2==0:
print("Even")
else:
print("Odd")
|
p03455
|
a,b = list(map(int,input().split()))
if a*b%2==0:
print("Even")
else:
print("Odd")
|
a,b = list(map(int,input().split()))
c = a*b
print(("Odd" if c%2==1 else "Even"))
|
p03455
|
# #! /bin/python
# a = int(input())
# b,c = map(int,input().split())
# s = input()
# print('{} {}'.format(a+b+c,s))
# 11 22 といった形で標準入力を数値で受け取る。
a,b = list(map(int,input().split()))
# if (not (1 <= a <= 10000)) or (not (1 <= b <= 10000)):
# print('over flow argument!')
# exit()
if 1 <= a <= 10000:
if 1 <= b <= 10000:
pass
else:
exit()
def checkEvenOdd(a,b):
mult = a * b
if mult % 2:
print('Odd')
else:
print('Even')
checkEvenOdd(a,b)
|
# #! /bin/python
# a = int(input())
# b,c = map(int,input().split())
# s = input()
# print('{} {}'.format(a+b+c,s))
# 11 22 といった形で標準入力を数値で受け取る。
a,b = list(map(int,input().split()))
# if (not (1 <= a <= 10000)) or (not (1 <= b <= 10000)):
# print('over flow argument!')
# exit()
def checkEvenOdd(a,b):
mult = a * b
if mult % 2:
print('Odd')
else:
print('Even')
checkEvenOdd(a,b)
|
p03455
|
a,b = list(map(int,input().split()))
if(a * b) % 2 == 0 :
print("Even")
else:
print("Odd")
|
x,y = map(int,input().split())
print('Even') if((x*y%2) == 0) else print('Odd')
|
p03455
|
a, b = list(map(int, input().split()))
print(('EOvdedn'[a*b%2::2]))
|
print(('EOvdedn'[eval(input().replace(' ', '*'))%2::2]))
|
p03455
|
num1, num2 = list(map(int,input().split()))
if num1 * num2 % 2 ==0:
print('Even')
else:
print('Odd')
|
a, b = tuple(int(num) for num in input().split())
ab = a * b
if ab % 2:
print('Odd')
else:
print('Even')
|
p03455
|
a, b = list(map(int, input().split()))
print(("Even" if a*b % 2 == 0 else "Odd"))
|
a, b = list(map(int, input().split()))
if a*b%2 == 0:
print("Even")
else:
print("Odd")
|
p03455
|
d, g = list(map(int, input().split()))
if d * g % 2 == 1:
print('Odd')
else:
print('Even')
|
d, g = list(map(int, input().split()))
if d % 2 == 1 and g % 2 == 1:
print('Odd')
else:
print('Even')
|
p03455
|
a, b = list(map(int, input().split()))
if a % 2 != 0 and b % 2 != 0:
print('Odd')
else:
print('Even')
|
a, b = list(map(int, input().split()))
m = a * b
if m % 2 != 0:
print('Odd')
else:
print('Even')
|
p03455
|
a, b = list(map(int, input().split()))
if a * b % 2 == 0:
print('Even')
else:
print('Odd')
|
# -*- coding: utf-8 -*-
def main():
a, b = list(map(int, input().split()))
print((['Even', 'Odd'] [a * b % 2]))
if __name__ == '__main__':
main()
|
p03455
|
a, b = list(map(int, input().split()))
print(("Even" if a*b % 2 == 0 else "Odd"))
|
a,b = list(map(int,input().split()))
num = a * b
if num % 2 == 0:
print("Even")
else:
print("Odd")
|
p03455
|
a , b = list(map(int,input().split()))
if (a * b)%2 ==0:
print("Even")
else:
print("Odd")
|
# ABC 086
A,B= list(map(int,input().split()))
if (A* B)%2==0:
ans ='Even'
else:
ans='Odd'
print(ans)
|
p03455
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.