This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include "tickets.h"
using namespace std;
using ll = long long;
const int inf = 1e9;
#ifdef ONPC
#define debug(args...) {cout << "[" << #args << "]: "; debug_out(args);}
#else
#define debug(args...) {42;}
#endif
void debug_out() {
cout << endl;
}
template<typename H, typename... T>
void debug_out(vector<H> h, T... t) {
cout << "{";
for (H i : h) cout << i << ", ";
cout << "}, ";
debug_out(t...);
}
template<typename H, typename... T>
void debug_out(H h, T... t) {
cout << h << ", ";
debug_out(t...);
}
long long find_maximum(int k, std::vector<std::vector<int>> x) {
int n = x.size();
int m = x[0].size();
vector<int> use(n);
int c1 = 0;
for (int i = 0; i < n; i++) {
use[i] = k;
for (int j = 0; j < k; j++) {
c1 += x[i][j];
}
}
int good = n / 2 * k;
debug(good, c1, use);
for (int i = 0; i < n; i++) {
while (c1 < good && use[i]) {
c1 -= x[i][use[i] - 1];
c1 += x[i][m - 1 - k + use[i]];
debug(i, m-1 - k + use[i]);
use[i]--;
}
}
debug(good, c1, use);
vector type(n, vector<int>(m, 0));
vector<tuple<int,int,int>> big;
for (int i = 0; i < n; i++) {
for (int j = 0; j < use[i]; j++) {
big.emplace_back(x[i][j], i, j);
}
for (int j = 0; j < k - use[i]; j++) {
big.emplace_back(x[i][m - 1 - j], i, m-1-j);
}
}
sort(big.begin(), big.end());
assert((int)big.size() == n * k);
for (int i = 0; i < n * k; i++) {
int a = get<1>(big[i]);
int b = get<2>(big[i]);
type[a][b] = i < n / 2 * k ? -1 : 1;
}
ll sum = 0;
vector ans(n, vector<int>(m, -1));
int round_low = 0;
for (int i = 0; i < n; i++) {
debug(i, ans[i]);
for (int j = 0; j < m; j++) {
if (type[i][j] == -1) {
sum -= x[i][j];
ans[i][j] = round_low++;
if (round_low >= k) round_low -= k;
}
}
int round = round_low;
for (int j = 0; j < m; j++) {
if (type[i][j] == 1) {
sum += x[i][j];
ans[i][j] = round++;
if (round >= k) round -= k;
}
}
debug(i, ans[i]);
}
allocate_tickets(ans);
return sum;
}
Compilation message (stderr)
tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:10:25: warning: statement has no effect [-Wunused-value]
10 | #define debug(args...) {42;}
| ^~
tickets.cpp:43:5: note: in expansion of macro 'debug'
43 | debug(good, c1, use);
| ^~~~~
tickets.cpp:10:25: warning: statement has no effect [-Wunused-value]
10 | #define debug(args...) {42;}
| ^~
tickets.cpp:48:13: note: in expansion of macro 'debug'
48 | debug(i, m-1 - k + use[i]);
| ^~~~~
tickets.cpp:10:25: warning: statement has no effect [-Wunused-value]
10 | #define debug(args...) {42;}
| ^~
tickets.cpp:52:5: note: in expansion of macro 'debug'
52 | debug(good, c1, use);
| ^~~~~
tickets.cpp:10:25: warning: statement has no effect [-Wunused-value]
10 | #define debug(args...) {42;}
| ^~
tickets.cpp:76:9: note: in expansion of macro 'debug'
76 | debug(i, ans[i]);
| ^~~~~
tickets.cpp:10:25: warning: statement has no effect [-Wunused-value]
10 | #define debug(args...) {42;}
| ^~
tickets.cpp:92:9: note: in expansion of macro 'debug'
92 | debug(i, ans[i]);
| ^~~~~
# | 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... |