제출 #967762

#제출 시각아이디문제언어결과실행 시간메모리
967762stdfloatKnapsack (NOI18_knapsack)C++17
49 / 100
2 ms2432 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int S, n; cin >> S >> n; vector<vector<pair<int, int>>> u(S + 1); while (n--) { int v, w, k; cin >> v >> w >> k; u[w].push_back({v, k}); } int mn = 0; vector<int> V, W; for (int i = 1; i <= S; i++) { if (u[i].empty()) continue; sort(u[i].rbegin(), u[i].rend()); int s = S / i; for (auto j : u[i]) { int mn = min(s, j.second); while (mn--) { V.push_back(j.first); W.push_back(i); } s -= mn; if (!s) break; } } assert((int)V.size() <= 22000); vector<ll> dp(S + 1, -1); dp[0] = 0; for (int i = 0; i < (int)V.size(); i++) { for (int j = S; j >= W[i]; j--) if (j - W[i] >= 0 && j - W[i] <= S && dp[j - W[i]] != -1) dp[j] = max(dp[j], dp[j - W[i]] + V[i]); } ll mx = 0; for (auto i : dp) mx = max(mx, i); cout << mx; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:20:6: warning: unused variable 'mn' [-Wunused-variable]
   20 |  int mn = 0;
      |      ^~
#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...