제출 #842582

#제출 시각아이디문제언어결과실행 시간메모리
842582GoldLightKnapsack (NOI18_knapsack)C++17
100 / 100
56 ms2496 KiB
#include <bits/stdc++.h> using namespace std; void fast(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);} map<int, vector<pair<int,int>>> mp; int main(){ fast(); int m, n; cin>>m>>n; for(int i=1; i<=n; i++){ int v, w, k; cin>>v>>w>>k; if(w<=m) mp[w].push_back({v, k}); } vector<long long> dp(m+1); dp[0]=0; for(auto &[w, items]:mp){ sort(items.begin(), items.end(), greater<pair<int,int>>()); for(int i=m; i>=1; i--){ int cop=0, copnow=0, idx=0; long long val=0; while(idx<items.size() && (cop+1)*w<=i){ cop++; copnow++; val+=items[idx].first; dp[i]=max(dp[i], dp[i-cop*w]+val); if(copnow==items[idx].second){ copnow=0; idx++; } } } } cout<<dp[m]; } /* const int N=2e3; long long dp[N+1]; int main(){ fast(); int s, n, v, w, k; cin>>s>>n; for(int i=1; i<=n; i++){ cin>>v>>w>>k; for(int j=s; j>=1; j--){ for(int l=1; l<=k; l++){ if(j<w*l) break; dp[j]=max(dp[j], dp[j-w*l]+1ll*v*l); } } } cout<<dp[s]; }*/

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:20:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |             while(idx<items.size() && (cop+1)*w<=i){
      |                   ~~~^~~~~~~~~~~~~
#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...