Submission #523506

#TimeUsernameProblemLanguageResultExecution timeMemory
523506aminKnapsack (NOI18_knapsack)C++14
Compilation error
0 ms0 KiB
include <bits/stdc++.h> using namespace std; long long a[1000]; long long w[50000],va[50000],t[50000]; long long dp[50000],d[50000]; int main() { long n; long m; cin>>m; cin>>n; vector<pair<long long,long long >>v[50000]; for(long i=0;i<n;i++) { cin>>va[i]>>w[i]>>t[i]; v[w[i]].push_back({-va[i],t[i]}); } for(long i=0;i<=m;i++) { sort(v[i].begin(),v[i].end()); } for(long i=0;i<=m;i++) { for(long y=0 ;y<v[i].size();y++) { v[i][y].first*=-1; //cout<<v[i][y].first; } dp[i]=-1; d[i]=-1; } dp[0]=0; d[0]=0; long long x=0; long long sum=0; for(long i=0;i<=m;i++) { for(long y=0;y<=m;y++) { dp[y]=d[y]; } if(v[i].size()>0) for(long y=0;y<=m;y++) { if(dp[y]!=-1) { x=0; long long b=0; sum=v[i][b].second; for(long u=i;u+y<=m;u+=i) { x+=v[i][b].first; d[y+u]=max(d[y+u],dp[y]+x); sum--; if(sum<=0) { b++; if(b>=v[i].size()) break; sum=v[i][b].second; } } } } } long long ans=0; for(long i=0;i<=m;i++) { ans=max(ans,d[i]); } cout<<ans; }

Compilation message (stderr)

knapsack.cpp:1:1: error: 'include' does not name a type
    1 | include <bits/stdc++.h>
      | ^~~~~~~
knapsack.cpp: In function 'int main()':
knapsack.cpp:11:1: error: 'cin' was not declared in this scope
   11 | cin>>m;
      | ^~~
knapsack.cpp:14:1: error: 'vector' was not declared in this scope
   14 | vector<pair<long long,long long >>v[50000];
      | ^~~~~~
knapsack.cpp:14:8: error: 'pair' was not declared in this scope
   14 | vector<pair<long long,long long >>v[50000];
      |        ^~~~
knapsack.cpp:14:13: error: expected primary-expression before 'long'
   14 | vector<pair<long long,long long >>v[50000];
      |             ^~~~
knapsack.cpp:18:2: error: 'v' was not declared in this scope
   18 |  v[w[i]].push_back({-va[i],t[i]});
      |  ^
knapsack.cpp:22:10: error: 'v' was not declared in this scope
   22 |     sort(v[i].begin(),v[i].end());
      |          ^
knapsack.cpp:22:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   22 |     sort(v[i].begin(),v[i].end());
      |     ^~~~
      |     short
knapsack.cpp:26:21: error: 'v' was not declared in this scope
   26 |     for(long y=0 ;y<v[i].size();y++)
      |                     ^
knapsack.cpp:48:8: error: 'v' was not declared in this scope
   48 |     if(v[i].size()>0)
      |        ^
knapsack.cpp:62:24: error: 'max' was not declared in this scope
   62 |                 d[y+u]=max(d[y+u],dp[y]+x);
      |                        ^~~
knapsack.cpp:81:9: error: 'max' was not declared in this scope
   81 |     ans=max(ans,d[i]);
      |         ^~~
knapsack.cpp:83:1: error: 'cout' was not declared in this scope
   83 | cout<<ans;
      | ^~~~