I have been trying to fix the bug in my code for this problem: https://oj.uz/problem/view/NOI18_knapsack. Any help would be very much appreciated.
Spoiler
Sorry about the bad format of the code, I don't know how to make it better.
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3792 |
| 2 | VivaciousAubergine | 3647 |
| 3 | Kevin114514 | 3611 |
| 4 | jiangly | 3583 |
| 5 | strapple | 3515 |
| 6 | tourist | 3470 |
| 7 | dXqwq | 3436 |
| 8 | Radewoosh | 3415 |
| 9 | Otomachi_Una | 3413 |
| 10 | Um_nik | 3376 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 163 |
| 2 | adamant | 150 |
| 3 | Um_nik | 146 |
| 4 | Dominater069 | 144 |
| 5 | errorgorn | 141 |
| 6 | cry | 139 |
| 7 | Proof_by_QED | 136 |
| 8 | YuukiS | 135 |
| 9 | chromate00 | 134 |
| 9 | TheScrasse | 134 |
Help Needed
I have been trying to fix the bug in my code for this problem: https://oj.uz/problem/view/NOI18_knapsack. Any help would be very much appreciated.
using namespace std;
typedef long long ll; const int MAX = 2002; vector<pair<ll, ll>> a[MAX]; ll f[MAX][MAX], s, n, u, v, w, k, total;
void solve() { cin >> s >> n; for (int i = 1; i <= n; i++) { cin >> v >> w >> k; a[w].push_back({v, k}); } for (int i = 1; i <= 2000; i++) sort(a[i].begin(), a[i].end(), greater<pair<ll, ll>>()); for (int i = 1; i <= s; i++) { for (int j = 1; j <= s; j++) { total = 0; ll temp = 0; f[i][j] = f[i — 1][j]; for (auto u : a[i]) { if (total + u.second * i <= j) { total += u.second * i; temp += u.second * u.first; f[i][j] = max(f[i][j], temp + f[i — 1][j — total]); } else { temp += (j — total) / i * u.first; total += (j — total) / i * i; f[i][j] = max(f[i][j], temp + f[i — 1][j — total]); break; } } f[i][j] = max(f[i][j], temp + f[i — 1][j — total]); //if (i > 19) cout << f[i][j] << " "; } //if (i > 19) cout << "\n"; } cout << f[s][s]; }
int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); solve(); }
Sorry about the bad format of the code, I don't know how to make it better.
| Name |
|---|


