# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
934467 | tnknguyen_ | Knapsack (NOI18_knapsack) | C++14 | 1038 ms | 18876 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 endl '\n'
#define pll pair<long long, long long>
const int sz = 1e6 + 5;
vector<pll> a;
long long f[sz];
long long s, n;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//freopen("main.inp","r",stdin);
//freopen("main.out","w",stdout);
cin>>s>>n;
for(int i=1;i<=n;++i){
long long v, w, k, p=1;
cin>>v>>w>>k;
while(p <= k){
k -= p;
a.push_back({v*p, w*p});
p *= 2;
}
if(k > 0){
a.push_back({v*k, w*k});
}
}
for(int i=0;i<a.size();++i){
for(int j=s;j>=a[i].second;--j){
f[j] = max(f[j], f[j - a[i].second] + a[i].first);
}
}
cout<<f[s];
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... |