結果

問題 No.288 貯金箱の仕事
コンテスト
ユーザー maspy
提出日時 2020-03-31 14:02:57
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 604 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 116 ms
コンパイル使用メモリ 85,488 KB
実行使用メモリ 62,840 KB
最終ジャッジ日時 2026-03-10 13:07:34
合計ジャッジ時間 3,777 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, readline().split())
A = tuple(map(int, readline().split()))
K = tuple(map(int, readline().split()))

M = sum(a * k for a, k in zip(A, K)) - M
if M < 0:
    print(-1)
    exit()

U = 26000
INF = 10 ** 18
dp = [INF] * U
dp[0] = 0
for a in A:
    for i in range(a, U):
        x = dp[i - a] + 1
        if dp[i] > x:
            dp[i] = x

n = A[-1]
k = max(0, (M - U) // n + 1)
M -= k * n
if dp[M] > 10 ** 17:
    print(-1)
else:
    print(dp[M] + k)
0