| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1319334 | quan123 | Knapsack (NOI18_knapsack) | C++20 | 1094 ms | 456 KiB |
#include <bits/stdc++.h>
#define int long long
using namespace std;
template<typename T, typename... Args>
void print(T t) {cout << t << '\n';}
template<typename T, typename... Args>
void print(T t, Args... args) {cout << t << " "; print(args...) ;}
const int S = 2005 , MX = 1e9+7;
int dp[S];
int n , s , ans = -MX;
void file_input() {
if (fopen("inp.txt" , "r")) {
freopen("inp.txt" , "r" , stdin);
freopen("out.txt" , "w" , stdout);
}
}
void add(int v , int w) {
for (int p = s-w; p >= 0; p--) {
if (dp[p] == -1) {continue;}
dp[p+w] = max(dp[p+w] , dp[p]+v);
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
file_input();
for (int i = 1; i < S; i++) {dp[i] = -1;}
cin >> s >> n;
while (n--) {
int a , b , k;
cin >> a >> b >> k;
int sm = k;
for (int p = 0; (k>>p) != 1; p++) {
add(a<<p , b<<p);
sm -= (1<<p);
}
add(a*sm , b*sm);
}
for (int p = 0; p <= s; p++) {ans = max(ans , dp[p]);}
cout << ans;
return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
