Submission #543044

#TimeUsernameProblemLanguageResultExecution timeMemory
543044LoboCarnival Tickets (IOI20_tickets)C++17
100 / 100
761 ms79272 KiB
#include "tickets.h" #include<bits/stdc++.h> using namespace std; const long long inf = (long long) 1e18 + 10; const int inf1 = (int) 1e9 + 10; // #define int long long #define ll long long #define dbl long double #define endl '\n' #define sc second #define fr first #define mp make_pair #define pb push_back #define all(x) x.begin(), x.end() const int maxn = 1600; int n, m, l[maxn], r[maxn]; long long find_maximum (int k, std::vector<std::vector<int>> x) { n = x.size(); m = x[0].size(); ll ans = 0; priority_queue<pair<int,int>> pq; for(int i = 0; i < n; i++) { for(int j = m-1; j >= m-k; j--) { ans+= x[i][j]; } l[i] = -1; r[i] = m-k; pq.push(mp(-x[i][l[i]+1]-x[i][r[i]],i)); } int aux = n*k/2; while(aux--) { int i = pq.top().sc; pq.pop(); ans-= x[i][l[i]+1] + x[i][r[i]]; l[i]++; r[i]++; if(r[i] != m) { pq.push(mp(-x[i][l[i]+1]-x[i][r[i]],i)); } } vector<vector<int>> s(n); for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { s[i].pb(-1); } } for(int j = 0; j < k; j++) { vector<pair<int,int>> v; for(int i = 0; i < n; i++) { v.pb(mp(l[i],i)); //maior o l[i], maior a quantidade de menores } sort(all(v)); for(int i = 0; i < n/2; i++) { int id = v[i].sc; //fica no maior s[id][r[id]] = j; r[id]++; } for(int i = n/2; i < n; i++) { int id = v[i].sc; //fica no menor s[id][l[id]] = j; l[id]--; } } // for(int i = 0; i < n; i++) { // for(int j = 0; j < m; j++) { // cout << s[i][j] << " "; // }cout << endl; // } allocate_tickets(s); return ans; } // int32_t main() { // ios::sync_with_stdio(false); cin.tie(0); // freopen("in.in", "r", stdin); // // freopen("out.out", "w", stdout); // int N,M,K; cin >> N >> M >> K; // vector<vector<int>> x(N); // for(int i = 0; i < N; i++) { // for(int j = 0; j < M; j++) { // int o; cin >> o; // x[i].pb(o); // } // } // cout << find_maximum(K,x); // }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...