結果
| 問題 | 
                            No.247 線形計画問題もどき
                             | 
                    
| コンテスト | |
| ユーザー | 
                             沙耶花
                         | 
                    
| 提出日時 | 2022-03-17 20:21:06 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 27 ms / 2,000 ms | 
| コード長 | 513 bytes | 
| コンパイル時間 | 3,753 ms | 
| コンパイル使用メモリ | 251,576 KB | 
| 最終ジャッジ日時 | 2025-01-28 10:02:17 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 23 | 
ソースコード
#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define Inf 1000000000000001
int main(){
	int n,c;
	cin>>c>>n;
	
	vector<long long> dp(c+1,Inf);
	dp[0] = 0;
	vector<int> a(n);
	rep(i,n)cin>>a[i];
	
	rep(i,n){
		rep(j,c+1){
			if(j-a[i]<0)continue;
			dp[j] = min(dp[j], dp[j-a[i]]+1);
		}
	}
	long long ans = dp.back();
	if(ans==Inf)ans = -1;
	cout<<ans<<endl;
	
	return 0;
}
            
            
            
        
            
沙耶花