Submission #625765

#TimeUsernameProblemLanguageResultExecution timeMemory
6257651neCarnival Tickets (IOI20_tickets)C++14
Compilation error
0 ms0 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; #include <vector> long long find_maximum(int k, std::vector<std::vector<int>> x) { int n = x.size(); int m = x[0].size(); vector<int>pos; for (int i = 0;i<n;++i){ for (int j = 0;j<m;++j){ sum+=x[i][j]; pos.push_back(x[i][j]); x[i][j] = 0; } } sort(pos.begin(),pos.end()); vector<int>valid = {pos[n/2],pos[n/2 - 1],sum / n,sum / n + 1,sum / n - 1}; long long ans = LLONG_MAX; for (auto x:valid){ long long curans = 0; for (auto y:pos){ curans+=abs(y - x); } ans = min(ans,curans); } for (int i = 0;i<n;++i){ for (int j = 0;j<m;++j){ x[i][j] = 0; } } allocate_tickets(x); return ans; }

Compilation message (stderr)

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:12:4: error: 'sum' was not declared in this scope
   12 |    sum+=x[i][j];
      |    ^~~
tickets.cpp:18:44: error: 'sum' was not declared in this scope
   18 |  vector<int>valid = {pos[n/2],pos[n/2 - 1],sum / n,sum / n  + 1,sum / n - 1};
      |                                            ^~~
tickets.cpp:18:76: error: could not convert '{pos.std::vector<int>::operator[](((std::vector<int>::size_type)(n / 2))), pos.std::vector<int>::operator[](((std::vector<int>::size_type)((n / 2) - 1))), <expression error>, <expression error>, <expression error>}' from '<brace-enclosed initializer list>' to 'std::vector<int>'
   18 |  vector<int>valid = {pos[n/2],pos[n/2 - 1],sum / n,sum / n  + 1,sum / n - 1};
      |                                                                            ^
      |                                                                            |
      |                                                                            <brace-enclosed initializer list>