#include "cross.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
long long SelectCross(int K, std::vector<int> I, std::vector<int> O) {
int N = I.size();
vector<pll> V; V.resize(N);
for(int i = 0 ; i < N ; i++) V[i].first = I[i], V[i].second = O[i];
sort(V.begin(), V.end());
reverse(V.begin(), V.end());
int cnt = 0;
map<ll, int> MP;
long long ans = 0;
for(int i = 0 ; i < N ; i++){
if(cnt == K) {
MP.begin()->second--; cnt--;
if(MP.begin()->second == 0) MP.erase(MP.begin());
}
MP[V[i].second]++; cnt++;
if(cnt == K){
ans = max(ans, V[i].first * V[i].first + (MP.begin()->first - V[i].first) * V[i].first * 2);
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
7 ms |
384 KB |
Output is correct |
5 |
Correct |
12 ms |
768 KB |
Output is correct |
6 |
Correct |
119 ms |
6756 KB |
Output is correct |
7 |
Correct |
118 ms |
6760 KB |
Output is correct |
8 |
Correct |
113 ms |
6764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
7 ms |
384 KB |
Output is correct |
5 |
Correct |
12 ms |
768 KB |
Output is correct |
6 |
Correct |
119 ms |
6756 KB |
Output is correct |
7 |
Correct |
118 ms |
6760 KB |
Output is correct |
8 |
Correct |
113 ms |
6764 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
7 ms |
384 KB |
Output is correct |
12 |
Correct |
13 ms |
768 KB |
Output is correct |
13 |
Correct |
63 ms |
3696 KB |
Output is correct |
14 |
Correct |
120 ms |
6764 KB |
Output is correct |
15 |
Correct |
119 ms |
6764 KB |
Output is correct |
16 |
Correct |
112 ms |
6764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
7 ms |
384 KB |
Output is correct |
5 |
Correct |
12 ms |
768 KB |
Output is correct |
6 |
Correct |
119 ms |
6756 KB |
Output is correct |
7 |
Correct |
118 ms |
6760 KB |
Output is correct |
8 |
Correct |
113 ms |
6764 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
256 KB |
Output is correct |
11 |
Correct |
7 ms |
384 KB |
Output is correct |
12 |
Correct |
13 ms |
768 KB |
Output is correct |
13 |
Correct |
63 ms |
3696 KB |
Output is correct |
14 |
Correct |
120 ms |
6764 KB |
Output is correct |
15 |
Correct |
119 ms |
6764 KB |
Output is correct |
16 |
Correct |
112 ms |
6764 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
6 ms |
512 KB |
Output is correct |
19 |
Correct |
17 ms |
1536 KB |
Output is correct |
20 |
Correct |
69 ms |
4208 KB |
Output is correct |
21 |
Correct |
96 ms |
5484 KB |
Output is correct |
22 |
Correct |
119 ms |
6764 KB |
Output is correct |
23 |
Correct |
116 ms |
6760 KB |
Output is correct |
24 |
Correct |
145 ms |
8680 KB |
Output is correct |
25 |
Correct |
230 ms |
14828 KB |
Output is correct |
26 |
Correct |
287 ms |
19176 KB |
Output is correct |