| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 975810 | Isam | Knapsack (NOI18_knapsack) | C++17 | 1060 ms | 1636 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt,fma")
#include<bits/stdc++.h>
using namespace std;
#define eb emplace_back
//#define int long long
inline int read() {
// opt = 0;
char ch = getchar();
int x = 0, f = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while ('0' <= ch && ch <= '9') {
x = (x << 1) + (x << 3) + ch - '0';
ch = getchar();
}
//if (ch == ' ') opt = 1;
return x * f;
}
constexpr int sz = 1e5 + 5;
constexpr long long inf = (long long)1E18 + 7;
int n, s;
struct ou{
int v, w, k;
} a[sz];
long long dp[2005];
signed main(){
s = read(), n = read();
for(register int i = 1; i <= n; ++i){
a[i].v = read(), a[i].w = read(), a[i].k = read();
a[i].k = min(a[i].k, s / a[i].w);
}
for(register int i = 1; i <= 2001; ++i){
dp[i] = -inf;
}
for(register int i = 1; i <= n; ++i){
for(register int ki = 1; ki <= a[i].k; ++ki)
for(register int j = s; j >= a[i].w; --j){
dp[j] = max(dp[j], dp[j - a[i].w] + a[i].v);
}
}
long long ans = *max_element(dp, dp+s+1);
cout << ans << '\n';
}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... | ||||
