#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define ff first
#define ss second
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define rep1(i, a, b) for (int i = (int)a; i >= (int)b; --i)
#define mp make_pair
#define vii vector<vector<int>>
#define ll long long
const int N = 2e5 + 5;
const ll inf = 2e9 + 5;
void allocate_tickets(vii a);
// void allocate_tickets(vii a) {
// int n = a.size(), m = a[0].size();
// rep(i, 0, n - 1) {
// rep(j, 0, m - 1) {
// cout << a[i][j] << ' ';
// }
// cout << '\n';
// }
// }
struct ticket{
int color, order, value;
};
bool operator < (const ticket &x, const ticket &y) {
return x.value < y.value;
}
ll find_maximum(int k, vii a) {
function<int()> sub1 = [&]() {
int n = a.size();
vector<int> v(n);
rep(i, 0, n - 1) v[i] = a[i][0];
sort(all(v));
int bound = v[n / 2];
int prize = 0;
rep(i, 0, n - 1) prize += abs(v[i] - bound);
rep(i, 0, n - 1) a[i][0] = 0;
allocate_tickets(a);
return prize;
};
function<ll()> sub2 = [&]() {
int n = a.size(), m = a[0].size();
vii allo(n, vector<int> (m));
ll prize = 0;
vector<ticket> Replace;
vector<int> Plus(n + 1);
rep(i, 0, n - 1) {
rep1(j, m - 1, m - k) {
prize += a[i][j];
allo[i][j] = 1;
}
rep(j, 0, k - 1) {
ticket tmp;
tmp.color = i;
tmp.order = j;
tmp.value = a[i][j] + a[i][m - k + j];
Replace.push_back(tmp);
}
}
sort(all(Replace));
//cout<<"prize,m="<<prize<<' '<<m<<'\n';
rep(i, 1, k * (n / 2)) {
auto [color, order, value] = Replace[i - 1];
//cout<<"123="<<color<<' '<<order<<' '<<value<<'\n';
prize -= value;
--Plus[color];
allo[color][m - k + order] = 0;
allo[color][order] = -1;
}
vector<int> v(n);
rep(i, 0, n - 1) v[i] = i;
sort(all(v), [&](int x, int y) {
return Plus[x] < Plus[y];
});
vector<int> cnt(k);
// rep(i, 0, n - 1) {
// rep(j, 0, m - 1) {
// cout << allo[i][j] << ' ';
// }
// cout << '\n';
// }
rep(ii, 0, n - 1) {
int i = v[ii];
int start = 0;
while (start < k && cnt[start] >= n / 2) {++start;}
//cout<<"i,start="<<i<<' '<<start<<'\n';
vector<bool> used(m);
rep(j, 0, m - 1) {
if (allo[i][j] != -1) break;
if (start >= k) break;
allo[i][j] = start + 1;
++cnt[start];
used[start] = 1;
++start;
}
start = 0;
rep1(j, m - 1, 0) {
if (allo[i][j] != 1) break;
while (start < k && used[start]) ++ start;
if (start >= k) break;
allo[i][j] = start + 1;
++start;
}
}
rep(i, 0, n - 1) rep(j, 0, m - 1) --allo[i][j];
allocate_tickets(allo);
return prize;
};
return sub2();
}
// signed main() {
// //freopen("ticket.inp", "r", stdin);
// int n, m, k; cin >> n >> m >> k;
// vii a(n, vector<int> (m));
// rep(i, 0, n - 1) rep(j, 0, m - 1) cin >> a[i][j];
// cout << find_maximum(k, a);
// }
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
23 ms |
2564 KB |
Output is correct |
6 |
Correct |
576 ms |
51344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Incorrect |
0 ms |
288 KB |
Ticket 4 of color 3 is played on invalid day -2 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Incorrect |
1 ms |
208 KB |
Ticket 8 of color 4 is played on invalid day -2 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
464 KB |
Output is correct |
3 |
Incorrect |
2 ms |
464 KB |
Ticket 15 of color 2 is played on invalid day -2 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
464 KB |
Output is correct |
3 |
Incorrect |
2 ms |
464 KB |
Ticket 15 of color 2 is played on invalid day -2 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
716 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
23 ms |
2564 KB |
Output is correct |
12 |
Correct |
576 ms |
51344 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
208 KB |
Output is correct |
15 |
Incorrect |
0 ms |
288 KB |
Ticket 4 of color 3 is played on invalid day -2 |
16 |
Halted |
0 ms |
0 KB |
- |