This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <cassert>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 101010
#define MAXS 20
#define INF 1000000000000000001
#define bb ' '
#define ln '\n'
#define Ln '\n'
double A[MAX];
double B[MAX];
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int N;
cin >> N;
int i;
double a, b;
for (i = 1; i <= N; i++) {
cin >> A[i] >> B[i];
}
sort(A + 1, A + N + 1);
sort(B + 1, B + N + 1);
double sa, sb;
int pa, pb;
pa = pb = N;
double ans = 0;
sa = sb = 0;
for (i = 1; i <= 2 * N; i++) {
if ((sa < sb && pa) || !pb) {
sa += A[pa];
pa--;
}
else {
sb += B[pb];
pb--;
}
ans = max(ans, min(sa, sb) - i);
}
cout << fixed;
cout.precision(4);
cout << ans << ln;
}
Compilation message (stderr)
sure.cpp: In function 'int main()':
sure.cpp:24:9: warning: unused variable 'a' [-Wunused-variable]
24 | double a, b;
| ^
sure.cpp:24:12: warning: unused variable 'b' [-Wunused-variable]
24 | double a, b;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |