제출 #1101823

#제출 시각아이디문제언어결과실행 시간메모리
1101823bozocodeKnapsack (NOI18_knapsack)C++14
73 / 100
1063 ms592 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { cin.tie(0) -> sync_with_stdio(0); int S, N; cin >> S >> N; vector<ll> value(S + 1, -1); value[0] = 0; for (int i = 0; i < N; i++) { int v, w, c; cin >> v >> w >> c; vector<ll> tmp = value; for (int j = 0; j < w; j++) { multiset<ll> ms; for (int k = j; k < S - w + 1; k += w) { int idx = (k - j) / w; // cout << k << "\n"; // cout << ms.size() << "\n"; if (value[k] != -1) { ms.insert(value[k] - idx * v); } // cout << ms.size() << "\n"; //now what //erase idx - c if (idx >= c) { //we can't be erasing 0 every time bruh this is stupid // int ok = k - c * w; int oidx = (ok - j) / w; // cout << ok << endl; // cout << value[i][ok] << endl; // cout << *ms.begin() << endl; // cout << value[i][ok] - oidx * v << endl; // cout << endl; // cout << "erasing: " << value[i][oidx] - oidx * v << "\n"; if (ms.find(value[ok] - oidx * v) != ms.end()) { ms.erase(ms.find(value[ok] - oidx * v)); } } if (ms.empty()) { continue; } ll best = *ms.rbegin(); // cout << best << endl; tmp[k + w] = max(tmp[k + w], best + (idx + 1) * v); } } value = tmp; // cout << "\n"; } ll ans = 0; // for (int i = 0; i < N + 1; i++) { // for (int j = 0; j < S; j++) { // cout << value[i][j] << " "; // } // cout << "\n"; // } for (int i = 0; i < S + 1; i++) { ans = max(value[i], ans); } cout << ans << "\n"; }
#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...