結果

問題 No.115 遠足のおやつ
ユーザー DialBird
提出日時 2017-03-23 21:19:46
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 33 ms / 5,000 ms
コード長 718 bytes
コンパイル時間 228 ms
コンパイル使用メモリ 12,032 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2025-01-03 01:22:43
合計ジャッジ時間 2,805 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

N,D,K = [int(i) for i in input().split()]
okashi = [i+1 for i in range(N)]

# okashi[idx:]において、k個でd円ちょうどになる買い方があるか
def check(d, idx, k):
    target = okashi[idx:]
    # 金額が届かないか、個数が足りない場合は-1
    return sum(target[:k]) <= d and d <= sum(target[-k:])

if N < K:
    print(-1)
elif not check(D, 0, K):
    print(-1)
else:
    buy = []
    for i in okashi:
        if len(buy) == K - 1:
            last_okashi = D - sum(buy)
            buy.append(last_okashi)
            print(" ".join([str(i) for i in buy]))
            break

        if not check(D - (sum(buy) + i), i, K - (len(buy) + 1)):
            continue

        buy.append(i)
0