結果

問題 No.247 線形計画問題もどき
ユーザー Navier_Boltzmann
提出日時 2022-09-10 17:14:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 416 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 82,408 KB
実行使用メモリ 69,504 KB
最終ジャッジ日時 2024-11-26 21:58:37
合計ジャッジ時間 3,028 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

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