Submission #488600

#TimeUsernameProblemLanguageResultExecution timeMemory
488600A_DKnapsack (NOI18_knapsack)C++14
100 / 100
125 ms145556 KiB
#include <bits/stdc++.h> #define ii pair<int,int> #define F first #define S second using namespace std; const int N=2e3+100; const int NN=2e5+100; const int M=2e4+100; vector<int> vec; vector<int> w; int szz[N]; int sz; pair<ii,int> a[NN]; int dp[M][N]; void solve() { vec.push_back(0); w.push_back(0); int s,n; cin>>s>>n; for(int i=1;i<=n;i++){ scanf("%d",&a[i].F.F); scanf("%d",&a[i].F.S); scanf("%d",&a[i].S); } sort(a+1,a+n+1); reverse(a+1,a+n+1); for(int i=1;i<=n;i++){ while(a[i].S&&s>a[i].F.S*szz[a[i].F.S]){ a[i].S--; szz[a[i].F.S]++; vec.push_back(a[i].F.F); w.push_back(a[i].F.S); sz++; if(sz>=M){ return; } } } for(int i=1;i<=sz;i++){ for(int j=1;j<w[i];j++){ dp[i][j]=dp[i-1][j]; } for(int j=w[i];j<=s;j++){ dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+vec[i]); } } cout<<dp[sz][s]<<endl; } main() { //freopen("face.in","r",stdin); //freopen("face.out","w",stdout); int t=1; // cin>>t; while(t--){ solve(); } }

Compilation message (stderr)

knapsack.cpp:52:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   52 | main()
      | ^~~~
knapsack.cpp: In function 'void solve()':
knapsack.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         scanf("%d",&a[i].F.F);
      |         ~~~~~^~~~~~~~~~~~~~~~
knapsack.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         scanf("%d",&a[i].F.S);
      |         ~~~~~^~~~~~~~~~~~~~~~
knapsack.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         scanf("%d",&a[i].S);
      |         ~~~~~^~~~~~~~~~~~~~
#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...