# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
501376 | zhangjishen | Knapsack (NOI18_knapsack) | C++98 | 1088 ms | 17124 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.
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
template<typename T> bool chkmin(T &a, T b){return b < a ? a = b, 1 : 0;}
template<typename T> bool chkmax(T &a, T b){return b > a ? a = b, 1 : 0;}
typedef long long ll;
const int MAXN = 3e6 + 10, MAXS = 2e3 + 10;
ll s, n, v[MAXN], w[MAXN], f[MAXS];
int main(){
// input
scanf("%lld %lld", &s, &n);
ll a, b, c;
ll t = 0;
for(int i = 1; i <= n; i++){
scanf("%lld %lld %lld", &a, &b, &c);
for(ll p = 1; p <= c; p *= 2){
t++; c -= p;
v[t] = p * a;
w[t] = p * b;
}
if(c){
t++;
v[t] = c * a;
w[t] = c * b;
}
}
n = t;
// dp
memset(f, 0, sizeof(f));
for(int i = 1; i <= n; i++)
for(int j = s; j >= 1; j--)
if(w[i] <= j)
chkmax(f[j], f[j - w[i]] + v[i]);
printf("%lld\n", f[s]);
}
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... |