Submission #878992

#TimeUsernameProblemLanguageResultExecution timeMemory
878992HoangThongKnapsack (NOI18_knapsack)C++14
17 / 100
2 ms8796 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pll pair<long long,long long> #define all(v) v.begin(),v.end() #define pb push_back const long long maxn=1e6; const long long minn=-1e6; const long long inf=1e9+7; int n,w[maxn],v[maxn],k[maxn],s; ll dp[100001][2001]; void solve(){ dp[0][0]=0; for(int i=1;i<=n;i++){ for(int j=0;j<=s;j++){ dp[i][j]=dp[i-1][j]; if(j>=w[i]&&k[i]){ ll tg=dp[i][j]; dp[i][j]=max(dp[i][j],dp[i-1][j-w[i]]+v[i]); if(tg>dp[i][j]) k[i]--; } } } cout<<dp[n][s]; } main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>s>>n; for(int i=1;i<=n;i++){ cin>>v[i]>>w[i]>>k[i]; } solve(); // for(int i=1;i<=n;i++){ // cout<<v[i]<<" "<<w[i]<<" "<<k[i]<<endl; // } }

Compilation message (stderr)

knapsack.cpp:26:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   26 | 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...