#include "tickets.h"
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
struct A {
int x, i, j;
bool operator < (const A & o) const {
return x < o.x;
}
};
vector<vector<int>> answer;
priority_queue<A> heap;
int roundcnt = 0;
void setanswer (vector<int> round) {
for (int i = 0; i < round.size(); i++) {
answer[i][round[i]] = roundcnt;
}
roundcnt++;
}
long long find_maximum(int k, vector<vector<int>> x) {
int n = x.size();
int m = x[0].size();
answer = vector<vector<int>>(n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
answer[i].push_back(-1);
}
}
vector<A> mn, mx;
for (int i = 0; i < n; i++) {
vector<pair<int,int>> temp;
for (int j = 0; j < m; j++) {
temp.push_back({x[i][j], j});
}
sort(all(temp));
mn.push_back({temp[0].first, i, temp[0].second});
mx.push_back({temp.back().first, i, temp.back().second});
}
long long sum = 0;
vector<int> round (n);
for (int i = 0; i < n; i++) sum += mx[i].x;
for (int i = 0; i < n; i++) round[i] = mx[i].j;
for (int i = 0; i < n; i++) heap.push({-mx[i].x-mn[i].x, i, mn[i].j});
int cnt = 0;
while (!heap.empty() and cnt < n/2) {
auto t = heap.top(); heap.pop();
sum += t.x;
round[t.i] = t.j;
cnt++;
}
setanswer(round);
allocate_tickets(answer);
return sum;
}
Compilation message
tickets.cpp: In function 'void setanswer(std::vector<int>)':
tickets.cpp:18:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for (int i = 0; i < round.size(); i++) {
| ~~^~~~~~~~~~~~~~
# |
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 |
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 |
3 ms |
460 KB |
Output is correct |
5 |
Correct |
29 ms |
2608 KB |
Output is correct |
6 |
Correct |
708 ms |
54632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 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 |
1 ms |
204 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 |
1 ms |
204 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 |
1 ms |
204 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 |
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 |
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 |
3 ms |
460 KB |
Output is correct |
11 |
Correct |
29 ms |
2608 KB |
Output is correct |
12 |
Correct |
708 ms |
54632 KB |
Output is correct |
13 |
Incorrect |
1 ms |
204 KB |
There is no ticket of color 0 on day 1 |
14 |
Halted |
0 ms |
0 KB |
- |