#ifndef _DEBUG
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#ifndef _DEBUG
#include "tickets.h"
#endif
#ifdef _DEBUG
#include <vector>
long long find_maximum(int k, std::vector<std::vector<int>> d);
void allocate_tickets(std::vector<std::vector<int>> _x);
#endif
#include <vector>
long long find_maximum(int k, std::vector<std::vector<int>> x)
{
int n = x.size();
int m = x[0].size();
std::vector<std::vector<int>> answer(n, vector<int>(m, -1));
priority_queue<pair<int64_t, int>> pq;
long long sol = 0;
for (int i = 0; i < n; i++)
{
sol -= x[i][0];
pq.push(pair<int64_t, int>{x[i].back() + x[i][0], i});
answer[i][0] = 0;
}
for (int l = 0; l < n * k / 2; l++)
{
auto [val, i] = pq.top();
pq.pop();
answer[i][0] = -1;
answer[i].back() = 0;
sol += val;
}
allocate_tickets(answer);
return sol;
}
#ifdef _DEBUG
#include <cassert>
#include <cstdio>
#include <vector>
#include <string>
static int n;
static int m;
static int k;
static std::vector<std::vector<int>> d;
static std::vector<std::vector<int>> x;
static int called = 0;
static void check(bool cond, std::string message)
{
if (!cond)
{
printf("%s\n", message.c_str());
exit(0);
}
}
void allocate_tickets(std::vector<std::vector<int>> _d)
{
check(!called, "allocate_tickets called more than once");
d = _d;
check((int)d.size() == n, "allocate_tickets called with parameter of wrong size");
for (int i = 0; i < n; i++)
{
check((int)d[i].size() == m, "allocate_tickets called with parameter of wrong size");
}
called = 1;
}
int main()
{
assert(scanf("%d %d %d", &n, &m, &k) == 3);
x.resize(n);
for (int i = 0; i < n; i++)
{
x[i].resize(m);
for (int j = 0; j < m; j++)
{
assert(scanf("%d", &x[i][j]) == 1);
}
}
fclose(stdin);
long long answer = find_maximum(k, x);
check(called, "failure to call allocate_tickets");
printf("%lld\n", answer);
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (j)
printf(" ");
printf("%d", d[i][j]);
}
printf("\n");
}
fclose(stdout);
return 0;
}
#endif
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
16 ms |
2384 KB |
Output is correct |
6 |
Correct |
437 ms |
51404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
There is no ticket of color 0 on day 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
There is no ticket of color 0 on day 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
There is no ticket of color 0 on day 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
There is no ticket of color 0 on day 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
16 ms |
2384 KB |
Output is correct |
12 |
Correct |
437 ms |
51404 KB |
Output is correct |
13 |
Incorrect |
0 ms |
212 KB |
There is no ticket of color 0 on day 1 |
14 |
Halted |
0 ms |
0 KB |
- |