# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1078290 | mindiyak | Carnival Tickets (IOI20_tickets) | C++14 | 1 ms | 604 KiB |
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 "tickets.h"
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
using namespace std;
#define F first
#define S second
typedef long long ll;
ll 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));
if(m == 1){
ll val = 0;
vector<int> temp;
for (int i = 0; i < n; i++) {
answer[i][0] = 0;
temp.push_back(x[i][0]);
}
sort(temp.begin(),temp.end());
for (int i = 0; i < n/2; i++)val -= temp[i];
for (int i = n/2; i < n; i++)val += temp[i];
allocate_tickets(answer);
return val;
}
if(k == 1){
priority_queue<pair<int,int>> plus,minus;
for (int i = 0; i < n; i++)plus.push({x[i][m-1],i});
for (int i = 0; i < n; i++)minus.push({-x[i][0],i});
vector<int> used(n,0);
ll ans = 0;
for(int i = 0;i<n/2;i++){
ans += plus.top().F;
used[plus.top().S] = 1;
answer[plus.top().S][m-1] = 0;
plus.pop();
}
for(int i = 0;i<n/2;i++){
auto a = minus.top();minus.pop();
if(used[a.S]){
i--;
continue;
}
ans += a.F;
answer[a.S][0] = 0;
}
allocate_tickets(answer);
return ans;
}
}
Compilation message (stderr)
# | 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... |