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 "cross.h"
#include <bits/stdc++.h>
using namespace std;
long long SelectCross(int k, std::vector<int> I, std::vector<int> O) {
int n = I.size();
vector<vector<int>> a(n, vector<int>(2));
for(int i = 0; i < n; ++i){
a[i][0] = O[i];
a[i][1] = I[i];
}
sort(a.begin(), a.end());
priority_queue<int> mx;
priority_queue<int, vector<int>, greater<int>> mn;
long long ans = 0;
for(int i = n - 1; i >= 0; --i){
if(!(int)mx.size() || a[i][1] > mx.top()) mn.push(a[i][1]);
else mx.push(a[i][1]);
while((int)mn.size() >= k){
mx.push(mn.top());
mn.pop();
}
while((int)mn.size() < k - 1 && (int)mx.size()){
mn.push(mx.top());
mx.pop();
}
if(i + k <= n){
ans = max(ans, (long long)a[i][0] * a[i][0] - (long long)(a[i][0] - mx.top()) * (a[i][0] - mx.top()));
}
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |