結果
問題 | No.527 ナップサック容量問題 |
ユーザー |
![]() |
提出日時 | 2017-06-09 22:50:32 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 14 ms / 2,000 ms |
コード長 | 1,420 bytes |
コンパイル時間 | 939 ms |
コンパイル使用メモリ | 100,872 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-22 15:40:42 |
合計ジャッジ時間 | 2,154 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 37 |
ソースコード
#include <iostream>#include <string>#include <vector>#include <queue>#include <stack>#include <map>#include <algorithm>#include <sstream>#include <cmath>#include <set>#include <iomanip>#include <deque>#include <unordered_map>using namespace std;typedef long long ll;#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())ll N;vector<ll> v,w;ll V;ll dp[100010];int main() {cin >> N;v.resize(N);w.resize(N);REP(i,N) cin >> v[i] >> w[i];cin >> V;REP(i,100010) dp[i] = 0;REP(i,N) {RREP(j,100010) {if(j - w[i] >= 0) {dp[j] = max(dp[j],dp[j - w[i]] + v[i]);}}}ll ansmin = 1e9;ll ansmax = -1e9;for(int i=1; i<100010; i++) {if(dp[i] == V) {ansmin = min(ansmin,(ll)i);ansmax = max(ansmax,(ll)i);}}/*REP(i,11) cout << dp[i] << " " ;cout << endl;*/ll sum = 0;REP(i,w.size()) sum += w[i];if(sum < ansmax) {cout << ansmin << endl;cout << "inf" << endl;} else {cout << ansmin << endl;cout << ansmax << endl;}return 0;}