# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
864581 | thundereyex | Knapsack (NOI18_knapsack) | C++14 | 1060 ms | 5908 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;
int main(){
long long int n,k;
cin>>n>>k;
vector<vector<long long int>>v1;
vector<long long int>v2;
for(int i=0;i<k;i++){
long long int a,b,c;
cin>>a>>b>>c;
if(b<=n){
long long int g= n/b;
// for(int j=0;j<min(g,c);j++){
v2.push_back(a);
v2.push_back(b);
v2.push_back(min(g,c));
v1.push_back(v2);
v2.clear();
// }
}
// v2.clear();
}
vector<long long int>dp(n+1,0);
// sort(v1.begin(),v1.end(),greater<vector<int>>());
long long int max1=0;
for (int i = 1; i <= v1.size(); i++)
for (int j = n; j >= 0; j--)
for (int t = 0; t <= v1[i-1][2]; t++)
if (j >= v1[i-1][1] * t) {
dp[j] = max(dp[j], dp[j - v1[i-1][1] * t] + v1[i-1][0] * t);
}
cout<<dp[n]<<endl;
}
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... |