# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1107192 | Daniel_1997 | Knapsack (NOI18_knapsack) | C++17 | 1056 ms | 3920 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>
#pragma GCC optimizate("Ofast")
using namespace std;
///Error types :
#define rte std::vector<int>rtt(oo);
#define wa std::cout<<"d";
#define tle while(1){;}
#define ir exit(1);
///STL
#define pb push_back
#define pp pop
#define fr first
#define sc second
#define vec vector<int>
///General
#define ios ios_base::sync_with_stdio(0); cin.tie(0),cout.tie(0)
#define int long long
#define endl "\n"
#define oo 1e18
const int mod = 998244353;
int32_t main(){
int k,n;
cin >> k >> n;
vector<pair<int,pair<int,int> > >v(n);
for(int i = 0;i < v.size();i++){
cin >> v[i].fr >> v[i].sc.fr >> v[i].sc.sc;
if(v[i].sc.sc >= (k/v[i].sc.fr))v[i].sc.sc = (k/v[i].sc.fr);
}
int dp[k+1] = {};
for(int i = 0;i < v.size();i++){
for(int j = 0;j < v[i].sc.sc;j++){
for(int l = k;l >= v[i].sc.fr;l--){
dp[l]=max(dp[l],dp[l-v[i].sc.fr] + v[i].fr);
}
}
}
cout << dp[k] << endl;
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... |