Submission #762356

#TimeUsernameProblemLanguageResultExecution timeMemory
762356goodbyehanbyeolCrosses on the Grid (FXCUP4_cross)C++17
100 / 100
105 ms20044 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...