이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <cstdio>
#pragma GCC optimize("O3")
#define endl '\n'
using namespace std;
void allocate_tickets(vector <vector <int> > r);
long long find_maximum(int k, vector <vector <int> > x) {
int n = (int)x.size(), m = (int)x[0].size();
vector <int> taken(n, k);
long long ans = 0;
int balance = 0;
priority_queue <pair <int, int> > pq;
for (int i = 0; i < n; i++) {
for (int j = m - k; j < m; j++)
ans += x[i][j];
taken[i] = k;
balance += k;
pq.push({-x[i][m-k]-x[i][0], i});
}
while (balance > 0) {
pair <int, int> curr = pq.top();
pq.pop();
ans += curr.first;
balance -= 2;
taken[curr.second]--;
if (taken[curr.second] != 0)
pq.push({-x[curr.second][m-taken[curr.second]]-x[curr.second][k-taken[curr.second]], curr.second});
}
vector <vector <int> > r(n, vector <int> (m, -1));
vector <int> cnt0(n, 0), cnt1(n, 0);
for (int i = 0; i < k; i++) {
vector <pair <int, int> > v;
for (int j = 0; j < n; j++)
v.push_back({(taken[j] - cnt1[j]) - (k - taken[j] - cnt0[j]), j});
sort (v.begin(), v.end());
for (int j = 0; j < n / 2; j++)
r[v[j].second][cnt0[v[j].second]] = i, cnt0[v[j].second]++;
for (int j = n / 2; j < n; j++)
r[v[j].second][m-taken[v[j].second]+cnt1[v[j].second]] = i, cnt1[v[j].second]++;
}
allocate_tickets(r);
/*
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++)
cout << r[i][j] << " ";
cout << endl;
}
*/
return ans;
}
/*
int n, m, k;
int main() {
cin >> n >> m >> k;
vector <vector <int> > x(n, vector <int> (m));
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> x[i][j];
cout << find_maximum(k, x) << endl;
}
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |