# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
672673 | tbzard | Carnival Tickets (IOI20_tickets) | C++14 | 588 ms | 73040 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 <bits/stdc++.h>
using namespace std;
void allocate_tickets(vector<vector<int> > s);
long long find_maximum(int k, vector<vector<int> > x){
int n = x.size(), m = x[0].size();
vector<vector<int> > s(n);
for(int i=0;i<n;i++) s[i].resize(m);
long long ans = -1;
vector<int> hi;
int idx = -1;
vector<pair<pair<int, int>, int> > y;
for(int i=0;i<n;i++){
y.push_back(make_pair(make_pair(x[i][0], x[i][m-1]), i));
}
sort(y.begin(), y.end());
for(int i=n/2-1;i<y.size();i++){
int val = y[i].first.first;
long long res = 0;
int rem = i-(n/2-1);
vector<pair<int, int> > best;
for(int j=0;j<i;j++){
res += val-y[j].first.first;
best.push_back(make_pair((y[j].first.second-val)-(val-y[j].first.first), y[j].second));
}
sort(best.begin(), best.end());
reverse(best.begin(), best.end());
vector<int> hii;
for(int j=0;j<rem;j++){
res += best[j].first;
hii.push_back(best[j].second);
}
for(int j=i+1;j<n;j++){
res += y[j].first.second - val;
hii.push_back(y[j].second);
}
if(ans < res){
ans = res;
hi = hii;
idx = i;
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
s[i][j] = -1;
}
}
for(int i=0;i<n/2;i++){
s[hi[i]][m-1] = 0;
}
for(int i=0;i<n;i++){
if(s[i][m-1] == -1) s[i][0] = 0;
}
allocate_tickets(s);
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... |