#include "wiring.h"
#include <bits/stdc++.h>
using namespace std;
long long min_total_length(vector<int> r_, vector<int> b_) {
set<int> r(r_.begin(), r_.end()), b(b_.begin(), b_.end());
long long ans = 0;
for (int x : r) {
if (b.empty()) {
auto it = upper_bound(b_.begin(), b_.end(), x);
if (it == b_.end()) --it;
else if (it != b_.begin() && x - *prev(it) < *it - x) --it;
ans += abs(*it - x);
} else {
auto it = b.upper_bound(x);
if (it == b.end()) --it;
else if (it != b.begin() && x - *prev(it) < *it - x) --it;
ans += abs(*it - x);
b.erase(it);
}
}
for (int x : b) {
auto it = r.upper_bound(x);
if (it == r.end()) --it;
else if (it != r.begin() && x - *prev(it) < *it - x) --it;
ans += abs(*it - x);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
3rd lines differ - on the 1st token, expected: '14340', found: '17422' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
35 ms |
9964 KB |
Output is correct |
4 |
Correct |
36 ms |
9932 KB |
Output is correct |
5 |
Correct |
43 ms |
9964 KB |
Output is correct |
6 |
Correct |
50 ms |
13156 KB |
Output is correct |
7 |
Correct |
50 ms |
13104 KB |
Output is correct |
8 |
Correct |
52 ms |
13192 KB |
Output is correct |
9 |
Correct |
67 ms |
13112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
3rd lines differ - on the 1st token, expected: '17703', found: '19704' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
3rd lines differ - on the 1st token, expected: '27', found: '34' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
3rd lines differ - on the 1st token, expected: '14340', found: '17422' |
3 |
Halted |
0 ms |
0 KB |
- |