제출 #1106582

#제출 시각아이디문제언어결과실행 시간메모리
1106582vjudge1Knapsack (NOI18_knapsack)C++17
100 / 100
43 ms3656 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int W, N; cin >> W >> N; vector<vector<pair<int, int>>> g(W + 1); vector<int> dp(W + 1); for (int i = 0; i < N; i++) { int v, w, k; cin >> v >> w >> k; if (w > W) continue; g[w].push_back({ -v,k }); } for (int i = 1; i <= W; i++) { if (g[i].empty()) continue; sort(g[i].begin(), g[i].end()); } for (int w = 1; w <= W; w++) { if (g[w].empty()) continue; int j = 0; for (int i = 1; i <= W / w; i++) { auto&& [v, k] = g[w][j]; for (int x = W; x - w >= 0; x--) { dp[x] = max(dp[x], dp[x - w] - v); } k--; if (k == 0) { j++; } if (j >= g[w].size()) { break; } } } cout << *max_element(dp.begin(), dp.end()); return 0; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:35:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |             if (j >= g[w].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...