#include <bits/stdc++.h>
template <class T> using Vec = std::vector<T>;
int parse() {
std::string s;
std::cin >> s;
const auto t = s.find('.');
if (t >= s.size()) {
return 10000 * std::stoi(s);
}
while (t + 4 >= s.size()) {
s.push_back('0');
}
return 10000 * std::stoi(s.substr(0, t)) + std::stoi(s.substr(t + 1));
}
int main() {
int N;
std::cin >> N;
Vec<int> A(N), B(N);
for (int i = 0; i < N; ++i) {
A[i] = parse();
B[i] = parse();
}
std::sort(A.rbegin(), A.rend());
std::sort(B.rbegin(), B.rend());
long long ok = 0, ng = 1000000000000 + 5;
while (ng - ok > 1) {
const auto md = (ok + ng) / 2;
int l = 0, r = 0;
long long ls = 0, rs = 0;
bool f = false;
for (int k = 1; k <= 2 * N; ++k) {
const auto need = md + k * 10000;
while (l < N and ls < need) {
ls += A[l];
l += 1;
}
while (r < N and rs < need) {
rs += B[r];
r += 1;
}
if (ls >= need and rs >= need and l + r <= k) {
f = true;
break;
}
}
(f ? ok : ng) = md;
}
std::cout << ok / 10000 << '.' << std::setw(4) << std::setfill('0') << ok % 10000 << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
288 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
2 ms |
204 KB |
Output is correct |
13 |
Correct |
2 ms |
204 KB |
Output is correct |
14 |
Correct |
3 ms |
300 KB |
Output is correct |
15 |
Correct |
2 ms |
204 KB |
Output is correct |
16 |
Correct |
2 ms |
304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
288 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
2 ms |
204 KB |
Output is correct |
13 |
Correct |
2 ms |
204 KB |
Output is correct |
14 |
Correct |
3 ms |
300 KB |
Output is correct |
15 |
Correct |
2 ms |
204 KB |
Output is correct |
16 |
Correct |
2 ms |
304 KB |
Output is correct |
17 |
Correct |
136 ms |
2464 KB |
Output is correct |
18 |
Correct |
127 ms |
2332 KB |
Output is correct |
19 |
Correct |
149 ms |
2372 KB |
Output is correct |
20 |
Correct |
138 ms |
2340 KB |
Output is correct |
21 |
Correct |
129 ms |
2808 KB |
Output is correct |
22 |
Correct |
120 ms |
2440 KB |
Output is correct |
23 |
Correct |
132 ms |
2332 KB |
Output is correct |
24 |
Correct |
139 ms |
2340 KB |
Output is correct |
25 |
Correct |
122 ms |
2336 KB |
Output is correct |
26 |
Correct |
138 ms |
2716 KB |
Output is correct |