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"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define N 1005
#define PB push_back
#define sz(x) int(x.size())
#define P 31
#define F first
#define M ll(1e9 + 7)
#define S second
#define all(x) x.begin(), x.end()
#define endl '\n'
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
//typedef tree<int, null_type, less_equal <int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ll mlt(ll a, ll b) {return (a * b) % M;}
ll sm(ll a, ll b) {return (a + b) % M;}
ll find_maximum(int k, vector<vector<int> > x)
{
int n = sz(x);
int m = sz(x[0]);
vector <vector <int> > r;
r.resize(n);
int lft[n];
memset(lft, 0, sizeof(lft));
for (int i = 0; i < n; i++)
r[i].resize(m, -1);
ll ans = 0;
vector <array <int, 2> > gr; gr.clear();
for (int i = 0; i < n; i++)
{
for (int j = 0; j < k; j++) ans -= x[i][j];
for (int j = 0; j < k; j++) gr.PB({x[i][k - j - 1] + x[i][m - j - 1], i});
}
sort(all(gr));
reverse(all(gr));
int kol[n];
memset(kol, 0, sizeof(kol));
for (int i = 0; i < n * k / 2; i++)
{
ans += gr[i][0];
kol[gr[i][1]]++;
}
for (int j = 0; j < k; j++)
{
vector <pair <int, int> > pr; pr.clear();
for (int i = 0; i < n; i++) pr.PB({kol[i], i});
sort(all(pr));
reverse(all(pr));
for (int i = 0; i < n / 2; i++)
{
kol[pr[i].S]--;
r[pr[i].S][m - kol[pr[i].S] - 1] = j;
}
for (int i = n / 2; i < n; i++) r[pr[i].S][lft[pr[i].S]++] = j;
}
allocate_tickets(r);
return ans;
}
//int main()
//{
// cout << find_maximum(4, {{2, 2, 2, 2}, {0, 3, 3, 3}, {0, 3, 3, 3}, {0, 3, 3, 3}}) << 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... |