結果
| 問題 | 
                            No.247 線形計画問題もどき
                             | 
                    
| コンテスト | |
| ユーザー | 
                             titia
                         | 
                    
| 提出日時 | 2022-08-17 04:20:06 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                MLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 444 bytes | 
| コンパイル時間 | 200 ms | 
| コンパイル使用メモリ | 82,468 KB | 
| 実行使用メモリ | 848,212 KB | 
| 最終ジャッジ日時 | 2024-10-04 00:37:23 | 
| 合計ジャッジ時間 | 3,897 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | -- * 5 | 
| other | AC * 2 MLE * 1 -- * 20 | 
ソースコード
from collections import deque
C=int(input())
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
Q=deque()
Q.append((0,0,C))# 回数, index, rest
ANS=1<<31
while Q:
    s,ind,rest=Q.popleft()
    if rest==0:
        ANS=min(ANS,s)
        continue
    if ind<N:
        
        x=rest//A[ind]
        for i in range(x+1):
            Q.append((s+i,ind+1,rest-i*A[ind]))
if ANS==1<<31:
    print(-1)
else:
    print(ANS)
            
            
            
        
            
titia