第7回日本情報オリンピック C - ダーツ
https://atcoder.jp/contests/joi2008ho/tasks/joi2008ho_c
提出
WA
code: python
from bisect import bisect_left
n, m = map(int, input().split())
score = int(input()) for _ in range(n)
score.sort()
# 3, 9, 14, 15
total = 0
first_idx = bisect_left(score, m-total)
if (first_idx == 0):
print(total)
exit()
total += scorefirst_idx-1
second_idx = bisect_left(score, m-total)
if (second_idx == 0):
print(total)
exit()
total += scoresecond_idx-1
third_idx = bisect_left(score, m-total)
if (third_idx == 0):
print(total)
exit()
total += scorethird_idx-1
forth_idx = bisect_left(score, m-total)
if (forth_idx == 0):
print(total)
exit()
total += scoreforth_idx-1
print(total)
解答
code: python
from bisect import bisect_right
n, m = map(int,input().split())
score = int(input()) for i in range(n)
# 取れない得点は排除
score = [scorei for i in range(n) if scorei <= m]
score.sort()
n = len(score)
# 1,2の合計
score_1_2 = set()
for i in range(n):
for j in range(n):
if scorei + scorej <= m:
score_1_2.add(scorei + scorej)
score_1_2 = list(score_1_2)
score_1_2.sort()
# 1,2の最大
ans = max(score-1, score_1_2-1)
# 3の最大
for i in range(n):
# 足せる最大の得点のインデックス
idx = bisect_right(score_1_2, m - scorei) - 1
if idx != -1:
ans = max(ans, scorei + score_1_2idx)
# 4の最大
for i in score_1_2:
idx = bisect_right(score_1_2, m - i) - 1
if idx != -1:
ans = max(ans, i + score_1_2idx)
print(ans)
テーマ
#bisect
蟻本 1-6 ハードルが上がった「くじびき」
提出
TLE
code: python
from itertools import product
n, m = list(map(int, input().split()))
p = int(input()) for _ in range(n)
p.append(0)
ans = -1
for i in product(p, repeat=4):
res = sum(i)
if res <= m and res > ans:
ans = res
print(ans)
解答
code: python
import bisect
n, m = map(int, input().split())
p = int(input()) for _ in range(n)
p.append(0)
s = sorted(pi + pj for i in range(n + 1) for j in range(n + 1))
res = 0
for a in s:
# M - a以下の最大の値のインデックス
index = bisect.bisect_left(s, m - a + 1) - 1
if index >= 0:
res = max(res, a + sindex)
print(res)
メモ
JOI 本選 2008 C - ダーツ (AOJ 0529, 難易度 6)