제출 #679660

#제출 시각아이디문제언어결과실행 시간메모리
679660nicolexxuuKnapsack (NOI18_knapsack)C++17
100 / 100
127 ms17508 KiB
#include <bits/stdc++.h> using namespace std; int main() { int S, N; cin >> S >> N; map<int, vector<pair<int, int>>> by_weight; for(int t = 0; t < N; t++) { int V, W, K; cin >> V >> W >> K; by_weight[W].push_back({V, K}); } vector<vector<int>> dp(by_weight.size()+1, vector<int>(S+1)); int res = 0; int i = 1; for(auto& hi : by_weight) { auto w = hi.first; auto items = hi.second; sort(items.begin(), items.end(), greater<pair<int, int>>()); for(int s = 1; s <= S; s++) { dp[i][s] = dp[i-1][s]; int curr_i = 0, curr_cnt = 0, val = 0; for(int cnt = 1; cnt * w <= s && curr_i < items.size(); cnt++) { val += items[curr_i].first; if(++curr_cnt == items[curr_i].second) { curr_cnt = 0; curr_i++; } dp[i][s] = max(dp[i][s], dp[i-1][s-cnt*w] + val); } } res = max(dp[i][S], res); i++; } cout << res << endl; }

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

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