結果

問題 No.247 線形計画問題もどき
コンテスト
ユーザー Navier_Boltzmann
提出日時 2022-09-10 17:14:43
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 416 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 280 ms
コンパイル使用メモリ 85,504 KB
実行使用メモリ 70,144 KB
最終ジャッジ日時 2026-05-21 05:59:24
合計ジャッジ時間 2,682 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import *
from itertools import *
from functools import *
from heapq import *
import math,sys
input = sys.stdin.readline

C = int(input())
N = int(input())
A = list(map(int,input().split()))

INF = (1<<60)
dp = [INF]*(C+2)

dp[0] = 0
for a in A:
    
    for i in range(C):
        
        dp[min(C+1,i+a)] = min(dp[min(C+1,i+a)],dp[i]+1)
        
if dp[C]==INF:
    print(-1)
else:
    print(dp[C])
0