This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#ifdef LOCAL
#else
#include "tickets.h"
#endif
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#ifdef LOCAL
#define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define dbg(...) 17;
#endif
template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; }
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) { bool f = true; os << "{"; for (const auto &x : c) { if (!f) os << ", "; f = false; os << x; } return os << "}"; }
template<typename T> void debug(string s, T x) { cerr << s << " = " << x << "\n"; }
template<typename T, typename... Args> void debug(string s, T x, Args... args) { cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...); }
#ifdef LOCAL
void allocate_tickets(vector<vector<int>> s) {
return;
}
#else
#endif
ll find_maximum(int k, vector<vector<int>> x) {
int n = x.size();
int m = x[0].size();
vector<vector<int>> res(n, vector<int>(m, -1));
if (m == 1) {
vector<int> all;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
res[i][j] = 0;
all.push_back(x[i][j]);
}
}
allocate_tickets(res);
sort(all.begin(), all.end());
ll ans = 0;
for (int i = 0; i < n; i++) {
if (i < n / 2) {
ans -= all[i];
} else {
ans += all[i];
}
}
return ans;
} else if (k == 1) {
vector<array<ll, 2>> use;
for (int i = 0; i < n; i++) {
use.push_back({x[i][0] + x[i][m - 1], i});
}
sort(use.begin(), use.end());
ll ans = 0;
for (int i = 0; i < n; i++) {
if (i < n / 2) {
res[use[i][1]][0] = 0;
ans -= x[use[i][1]][0];
} else {
res[use[i][1]][m - 1] = 0;
ans += x[use[i][1]][m - 1];
}
}
return ans;
}
return -1;
}
#ifdef LOCAL
int main() {
// freopen("file.in", "r", stdin);
// string line; cin >> line;
int n, m, k; cin >> n >> m >> k;
vector<vector<int>> s(n, vector<int>(m, 0));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> s[i][j];
}
}
find_maximum(k, s);
return 0;
}
#else
#endif
# | 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... |