#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<pair<int, int>> v;
for(int i=0; i<N; i++) v.emplace_back(I[i], O[i]);
sort(v.rbegin(), v.rend());
//for(int i=0;i <N; i++) cout << v[i].first << ' '; cout << endl;
//for(int i=0;i <N; i++) cout << v[i].second << ' '; cout << endl;
priority_queue<int, vector<int>, greater<int>> s;
for(int i=0; i<K-1; i++) {
s.push(v[i].second);
}
long long res = 0;
for(int i=K-1; i<N; i++) {
int ii = v[i].first;
int oo = s.size() ? min(s.top(), v[i].second) : v[i].second;
// cout << oo << ' ' << ii << endl;
res = max(res, 1LL*oo*oo - 1LL*(oo-ii)*(oo-ii));
s.push(v[i].second);
if((int)s.size() > K-1) s.pop();
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
432 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Correct |
12 ms |
768 KB |
Output is correct |
6 |
Correct |
112 ms |
5632 KB |
Output is correct |
7 |
Correct |
106 ms |
5740 KB |
Output is correct |
8 |
Correct |
114 ms |
5740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
432 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Correct |
12 ms |
768 KB |
Output is correct |
6 |
Correct |
112 ms |
5632 KB |
Output is correct |
7 |
Correct |
106 ms |
5740 KB |
Output is correct |
8 |
Correct |
114 ms |
5740 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
6 ms |
384 KB |
Output is correct |
11 |
Correct |
6 ms |
384 KB |
Output is correct |
12 |
Correct |
12 ms |
768 KB |
Output is correct |
13 |
Correct |
60 ms |
3184 KB |
Output is correct |
14 |
Correct |
110 ms |
5784 KB |
Output is correct |
15 |
Correct |
121 ms |
5760 KB |
Output is correct |
16 |
Correct |
119 ms |
5736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
432 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Correct |
12 ms |
768 KB |
Output is correct |
6 |
Correct |
112 ms |
5632 KB |
Output is correct |
7 |
Correct |
106 ms |
5740 KB |
Output is correct |
8 |
Correct |
114 ms |
5740 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
6 ms |
384 KB |
Output is correct |
11 |
Correct |
6 ms |
384 KB |
Output is correct |
12 |
Correct |
12 ms |
768 KB |
Output is correct |
13 |
Correct |
60 ms |
3184 KB |
Output is correct |
14 |
Correct |
110 ms |
5784 KB |
Output is correct |
15 |
Correct |
121 ms |
5760 KB |
Output is correct |
16 |
Correct |
119 ms |
5736 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
6 ms |
384 KB |
Output is correct |
19 |
Correct |
14 ms |
920 KB |
Output is correct |
20 |
Correct |
66 ms |
3184 KB |
Output is correct |
21 |
Correct |
93 ms |
5100 KB |
Output is correct |
22 |
Correct |
117 ms |
5740 KB |
Output is correct |
23 |
Correct |
116 ms |
5736 KB |
Output is correct |
24 |
Correct |
120 ms |
5740 KB |
Output is correct |
25 |
Correct |
124 ms |
6632 KB |
Output is correct |
26 |
Correct |
116 ms |
6884 KB |
Output is correct |