제출 #956271

#제출 시각아이디문제언어결과실행 시간메모리
956271haileyyKnapsack (NOI18_knapsack)C++14
100 / 100
55 ms3924 KiB
//https://oj.uz/problem/view/NOI18_knapsack #include <bits/stdc++.h> #define loop(i, l, r) for(int i = (l); i < (r); ++i) #define pool(i, l, r) for(int i = (l); i > (r); --i) #define debug(x) cerr << #x << ": " << x << endl; using namespace std; int n,s; const int MAXS = 2005; long long dp[MAXS]; map<int,vector<pair<int,int>>> items; bool cmp(pair<int,int> a,pair<int,int> b){ return a.first>b.first; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin>>s>>n; long long v,w,k; loop(i,0,n){ cin>>v>>w>>k; items[w].push_back({v,k}); } for(auto& i:items){ vector<pair<int,int>>& a = i.second; sort(a.begin(),a.end(),cmp); pool(j,s,-1){ int value = 0; int c = 0; int count = 0; int l = 1; while(c<a.size()){ w = l*i.first; if(j>=w){ value+=a[c].first; count++; if(count>=a[c].second){ c++; count = 0; } dp[j] = max(dp[j],dp[j-w]+value); }else{ break; } l++; } } } cout<<dp[s]<<endl; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

knapsack.cpp: In function 'int main()':
knapsack.cpp:34:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |             while(c<a.size()){
      |                   ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...