Submission #657968

#TimeUsernameProblemLanguageResultExecution timeMemory
657968mychecksedadCarnival Tickets (IOI20_tickets)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define all(x) x.begin(), x.end()
 
void allocate_tickets(vector<vector<int>> _x);
 
long long find_maximum(int k, vector<vector<int>> _arr) {
    int N = _arr.size(), M = _arr[0].size();
    vector<vector<int>> answer;
    vector<vector<pair<int,int>>> arr(N);
    
    for (int i = 0; i < N; i++) {
        std::vector<int> row(M, -1);
        answer.push_back(row);
        for(int j = 0; j < m; ++j) arr[i].pb({_arr[i][j], j});
    }
    vector<vector<pair<int,int>>> unused(N), small(N);
    
    ll ans = 0;


    for(int i = 0; i < N; ++i){
        for(int j = 0; j < k; ++j) small[i].pb(arr[i][j]);
        for(int j = 0; j < M; ++j) unused[i].pb(arr[i][j]);
    }
    for(int i = 0; i < k; ++i){
        priority_queue<pair<int, int>> q;
        for(int j = 0; j < N; ++j){
            while(answer[j][unused[j].back().second] != -1) unused[j].pop_back();
            q.push({unused[j].back().first + small[j].back().first, j});
        }
        for(int j = 0; j < N; ++j){
            int v = q.top().second;
            q.pop();
            if(j < N/2){
                ans += unused[v].back().first;
                answer[v][unused[v].back().second] = i;
                unused[v].pop_back();
            }else{
                ans -= small[v].back().first;
                answer[v][small[v].back().second - 1] = i;
            }
            small[v].pop_back();
        }
    }


 
    allocate_tickets(answer);
    return ans;
}

Compilation message (stderr)

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:17:28: error: 'm' was not declared in this scope
   17 |         for(int j = 0; j < m; ++j) arr[i].pb({_arr[i][j], j});
      |                            ^