Submission #696911

#TimeUsernameProblemLanguageResultExecution timeMemory
696911khanhtaiKnapsack (NOI18_knapsack)C++14
12 / 100
2 ms340 KiB
#include<bits/stdc++.h> #define int long long #define pb push_back #define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); #define MOD 1000000007 #define INF 1e18 #define fi first #define se second #define FOR(i,a,b) for(int i=a;i<=b;i++) #define FORD(i,a,b) for(int i=a;i>=b;i--) #define sz(a) ((int)(a).size()) #define endl '\n' #define pi 3.14159265359 #define TASKNAME "knapsack" using namespace std; typedef pair<int,int> ii; typedef pair<int,ii> iii; typedef vector<int> vi; const int MAXN = 1e5 + 9; int dp[2][MAXN],s[MAXN],w[MAXN],k[MAXN]; int n,S; main() { fast; // freopen(TASKNAME".inp","r",stdin); // freopen(TASKNAME".out","w",stdout); cin>>S>>n; for(int i=1;i<=n;i++){ cin>>s[i]>>w[i]>>k[i]; } for(int i=1;i<=n;i++){ int ii = i&1; for(int j=1;j<=S;j++){ for(int t=1;t<=min(j/w[i],k[i]);t++){ dp[ii][j] = max(dp[ii][j],dp[!ii][j]); if (j>= t*w[i]){ dp[ii][j] = max(dp[!ii][j-t*w[i]] + t*s[i], dp[ii][j]); } } } } cout<<dp[n&1][S]<<endl; }

Compilation message (stderr)

knapsack.cpp:22:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   22 | main()
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...