제출 #974708

#제출 시각아이디문제언어결과실행 시간메모리
974708vjudge1Knapsack (NOI18_knapsack)C++14
73 / 100
5 ms1372 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; ll dp[2005], ans; tuple<int, int, int> arr[10005]; priority_queue<int, vector<int>, greater<int>> pq[2005]; vector<pair<int, int>> item; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int s, n, k, v, w; cin >> s >> n; for (int i = 0; i < n; i++) { cin >> v >> w >> k; arr[i] = make_tuple(v, w, k); } sort(arr, arr + n, greater<tuple<int, int, int>>()); for (int i = 0; i < n; i++) { tie(v, w, k) = arr[i]; k = min(k, s / w); while (k--) { pq[w].push(v); if (pq[w].size() > s / w) break; } } for (int i = 1; i <= s; i++) { while (!pq[i].empty()) { item.push_back({i, pq[i].top()}); pq[i].pop(); } } for (auto& p : item) { tie(w, v) = p; for (int j = s; j >= 0; j--) { if (dp[j] == 0 && j != 0) continue; if (w + j <= s) dp[w + j] = max(dp[w + j], dp[j] + v); } } for (int i = 0; i <= s; i++) { ans = max(ans, dp[i]); } cout << ans << "\n"; return 0; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:27:30: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |             if (pq[w].size() > s / w)
      |                 ~~~~~~~~~~~~~^~~~~~~
#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...