제출 #1083797

#제출 시각아이디문제언어결과실행 시간메모리
1083797Kiet07Knapsack (NOI18_knapsack)C++14
100 / 100
53 ms4056 KiB
#include<bits/stdc++.h> using namespace std; long long dp[10005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen("TEST.inp","r",stdin); //freopen("dpknste2.inp","r",stdin); // freopen("dpknste2.out","w",stdout); int n,m; cin>>m>>n; map<int,vector<pair<int,int>>>mp; for(int i=1;i<=n;i++) { int x,y,z; cin>>y>>x>>z; mp[x].push_back({y,z}); } for(auto it:mp) { sort(it.second.begin(),it.second.end(),greater<pair<int,int>>()); for(int j=m;j>=it.first;j--) { int cur_i=0,cnt=0,copy=0; long long profit=0; while((copy+1)*it.first<=j&&cur_i<it.second.size()) { copy++; cnt++; profit+=1ll*it.second[cur_i].first; dp[j]=max(dp[j],dp[j-copy*it.first]+profit); if(cnt==it.second[cur_i].second) { cnt=0; cur_i++; } } } } cout<<dp[m]; return 0; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:25:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |    while((copy+1)*it.first<=j&&cur_i<it.second.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...