Submission #524818

#TimeUsernameProblemLanguageResultExecution timeMemory
524818rsjwKnapsack (NOI18_knapsack)C++14
Compilation error
0 ms0 KiB
#include <cstdio> #include <algorithm> using namespace std; int v[100010],w[100010],k[100010]; vector<pair<int,int>> a[2005]; int V[26000],W[26000],N,f[2010]; void add(int x,int y,int t=1){ while(t--)N++,V[N]=x,W[N]=y; } int main(){ int m,n,i,j; scanf("%d%d",&m,&n); for(i=1;i<=n;i++)scanf("%d%d%d",&v[i],&w[i],&k[i]); for(i=1;i<=n;i++)a[w[i]].push_back(make_pair(-v[i],k[i])); for(i=1;i<=m;i++){ sort(a[i].begin(),a[i].end()); int count=(m+i-1)/i; for(auto j:a[i]){ if(count==0)break; add(-j.first,i,min(count,j.second)); count-=min(count,j.second); } } for(i=1;i<=N;i++) for(j=m;j>=w[i];j--) f[j]=max(f[j],f[j-w[i]]+v[i]); printf("%d",f[m]); return 0; }

Compilation message (stderr)

knapsack.cpp:5:1: error: 'vector' does not name a type
    5 | vector<pair<int,int>> a[2005];
      | ^~~~~~
knapsack.cpp: In function 'int main()':
knapsack.cpp:14:19: error: 'a' was not declared in this scope
   14 |  for(i=1;i<=n;i++)a[w[i]].push_back(make_pair(-v[i],k[i]));
      |                   ^
knapsack.cpp:16:8: error: 'a' was not declared in this scope
   16 |   sort(a[i].begin(),a[i].end());
      |        ^
knapsack.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  scanf("%d%d",&m,&n);
      |  ~~~~~^~~~~~~~~~~~~~
knapsack.cpp:13:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  for(i=1;i<=n;i++)scanf("%d%d%d",&v[i],&w[i],&k[i]);
      |                   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~