Submission #1034171

#TimeUsernameProblemLanguageResultExecution timeMemory
1034171happy_nodeCarnival Tickets (IOI20_tickets)C++17
Compilation error
0 ms0 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const int MX=1505; int F[MX], B[MX], f[MX], b[MX]; int N,M; long long find_maximum(int K, std::vector<std::vector<int>> d) { N=d.size(); M=d[0].size(); priority_queue<pair<int,int>> pq; ll ans=0; for(int i=0;i<N;i++) { B[i]=M-K; for(int j=B[i];j<M;j++) ans+=d[i][j]; pq.push({-d[i][B[i]]-d[i][F[i]],i}); } int ops=N*K/2; while(pq.size() && ops>0) { auto [x,r]=pq.top(); pq.pop(); ans+=x; F[r]++; B[r]++; ops--; if(B[r]<M) pq.push({-d[r][B[r]]-d[r][F[r]],r}); } vector<pair<int,int>> v; for(int i=0;i<N;i++) { F[i]--; f[i]=0; b[i]=M-1; v.push_back({F[i],i}); } vector<vector<int>> s(N,vector<int>(M,-1)); for(int x=0;x<k;x++) { sort(v.rbegin(),v.rend()); for(int j=0;j<N/2;j++) { auto &[y,i]=v[j]; s[i][f[i]]=x; f[i]++; y--; } for(int j=N/2;j<N;j++) { auto &[y,i]=v[j]; s[i][b[i]]=x; b[i]--; } } allocate_tickets(s); return ans; }

Compilation message (stderr)

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:50:23: error: 'k' was not declared in this scope
   50 |         for(int x=0;x<k;x++) {
      |                       ^