이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
#define pb push_back
#define all(xs) xs.begin(), xs.end()
#define rep(i, n) for (int i=0; i<(n); i++)
using namespace std;
int N;
long long A[100000], B[100000];
int read_as_int() {
string s;
cin >> s;
int ret = 0;
bool after = false;
string t = "";
for (char c : s) {
if (c == '.') {
after = true;
continue;
}
if (after) t += c;
else ret = 10*ret + (int)(c-'0');
}
while (t.size() < 4) t += '0';
return 10000*ret + stoi(t);
}
signed main() {
cin >> N;
rep(i, N) {
A[i] = read_as_int();
B[i] = read_as_int();
}
sort(A, A+N, greater<long long>());
sort(B, B+N, greater<long long>());
rep(i, N-1) A[i+1] += A[i];
rep(i, N-1) B[i+1] += B[i];
int p = 0;
long long m = 0, s = 0;
rep(a, N) {
while (p < N && B[p] < A[a]) {
s = max(s, B[p] - 10000LL*(p+1));
p++;
}
m = max(m, s-10000LL*(a+1));
if (p < N) {
m = max(m, A[a] - 10000LL*(p+1+a+1));
}
}
printf("%.4lf\n", (double)m/10000.0);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |