結果
問題 |
No.527 ナップサック容量問題
|
ユーザー |
![]() |
提出日時 | 2020-04-04 23:43:05 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 20 ms / 2,000 ms |
コード長 | 714 bytes |
コンパイル時間 | 2,238 ms |
コンパイル使用メモリ | 197,324 KB |
最終ジャッジ日時 | 2025-01-09 14:10:01 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 37 |
ソースコード
#include<bits/stdc++.h> #define ALL(v) std::begin(v),std::end(v) using lint=long long; using lubl=long double; void cmx(lint&x,lint y){if(x<y)x=y;} int main(){ std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false); std::cout.setf(std::ios_base::fixed);std::cout.precision(15); lint lim=100'004; std::vector<lint>dp(lim); lint n;std::cin>>n; while(n--){ lint v,w;std::cin>>v>>w; for(lint i=lim-1-w;i>=0;i--){ cmx(dp.at(i+w),dp.at(i)+v); } } lint V;std::cin>>V; auto&&[lb,rb]=std::equal_range(ALL(dp),V); std::cout<<std::max(1ll,lint(lb-dp.begin()))<<'\n'; std::cout<<(rb==dp.end()?"inf":std::to_string(rb-dp.begin()-1))<<'\n'; }