結果
| 問題 |
No.527 ナップサック容量問題
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-04 13:24:39 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 44 ms / 2,000 ms |
| コード長 | 1,032 bytes |
| コンパイル時間 | 1,530 ms |
| コンパイル使用メモリ | 172,368 KB |
| 実行使用メモリ | 43,136 KB |
| 最終ジャッジ日時 | 2024-06-24 06:40:48 |
| 合計ジャッジ時間 | 3,594 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 37 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
int W = 100005;
int main(){
int n;
cin >> n;
vector<P> wv(n);
rep(i,n){
cin >> wv[i].second >> wv[i].first;
}
int V;cin >> V;
vector<vector<int>> dp(n+1,vector<int>(W,0));
for(int i=1;i<=n;i++){
rep(j,W){
if(j - wv[i-1].first >=0){
dp[i][j] = max(dp[i-1][j],dp[i-1][j-wv[i-1].first] + wv[i-1].second);
}else{
dp[i][j] = dp[i-1][j];
}
}
}
int mn = INF;
int mx = 0;
for(int j=1;j<W;j++){
if(dp[n][j] == V){
mn = min(mn,j);
mx = max(mx,j);
}
}
if(mx == W-1) mx = -1;
cout << mn << endl;
if(mx ==-1) cout << "inf" << endl;
else cout << mx << endl;
return 0;
}