結果
問題 |
No.527 ナップサック容量問題
|
ユーザー |
|
提出日時 | 2018-08-26 17:52:06 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 10 ms / 2,000 ms |
コード長 | 606 bytes |
コンパイル時間 | 599 ms |
コンパイル使用メモリ | 67,780 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-01 03:57:46 |
合計ジャッジ時間 | 2,083 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 37 |
ソースコード
#include<iostream> #include<algorithm> using namespace std; #define printb(x, a, b) if(x) cout << a << endl; else cout << b << endl int main(){ int n, v, w, V, sumV = 0; static int dp[100001] = {}; cin >> n; for(int i = 0; i < n; i++){ cin >> v >> w; for(int j = 100000; j >= w; j--) dp[j] = max(dp[j], dp[j-w]+v); sumV += v; } cin >> V; int minimum = lower_bound(dp, dp+100001, V) - dp; int maximum = upper_bound(dp, dp+100001, V) - 1 - dp; cout << max(1,minimum) << endl; printb(sumV == V, "inf", maximum); return 0; }