제출 #879116

#제출 시각아이디문제언어결과실행 시간메모리
879116AminMDNZKnapsack (NOI18_knapsack)C++17
100 / 100
118 ms35152 KiB
#include<bits/stdc++.h> using namespace std; int main(){ int n, s, v, w, num; cin>>s>>n; map<int, vector<pair<int,int>>> by_weight; for(int i=0;i<n;i++){ cin>>v>>w>>num; if(w <= s && num > 0) by_weight[w].push_back({v, num}); } vector<vector<long long>> dp(by_weight.size()+1, vector<long long> (s+1, INT_MIN)); int at = 1; dp[0][0] = 0; for(auto &[w, item] : by_weight){ sort(item.begin(), item.end(), greater<pair<int, int>>()); for(int i=0;i<=s;i++){ dp[at][i] = dp[at-1][i]; int ind = 0; num = 0; int cur_in = 0; long long price = 0; while(ind < item.size() && w * (num+1) <= i){ num++; price += item[ind].first; if(dp[at-1][i-w * num] != INT_MIN) dp[at][i] = max(dp[at][i], dp[at-1][i-w * num] + price); cur_in++; if(cur_in == item[ind].second) cur_in = 0, ind++; } } at++; } cout<<*max_element(dp.back().begin(), dp.back().end()); }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:23:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |             while(ind < item.size() && w * (num+1) <= 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...