이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define STIZE(x) fprintf(stderr, "STIZE%d\n", x);
#define PRINT(x) fprintf(stderr, "%s = %d\n", #x, x);
#define NL(x) printf("%c", " \n"[(x)]);
#define lld long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define all(a) begin(a),end(a)
#define sz(a) int((a).size())
#define LINF 1000000000000000
#define INF 1000000000
#define EPS 1e-9
using namespace std;
#define MAXN 100010
double a[MAXN], b[MAXN];
//double parca[MAXN], parcb[MAXN];
int an, bn;
int bs(double a[], double b[], int an, int l, int r) {
int rez = 0;
while(l <= r) {
int mid = (l+r)/2;
if(a[an]-mid >= b[mid]-an) rez = mid, l = mid+1;
else r = mid-1;
}
return rez;
}
int main() {
ios::sync_with_stdio(false);cin.tie(0);
int n; cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
}
sort(a+1, a+n+1);
sort(b+1, b+n+1);
reverse(a+1, a+n+1);
reverse(b+1, b+n+1);
for(int i = 1; i <= n; i++) {
if(a[i]-EPS >= 1.0) an = i;
if(b[i]-EPS >= 1.0) bn = i;
a[i] = max(0.0, a[i]-1);
b[i] = max(0.0, b[i]-1);
}
for(int i = 1; i <= an; i++) {
a[i] += a[i-1];
}
for(int i = 1; i <= bn; i++) {
b[i] += b[i-1];
}
double rez = 0;
for(int i = 1; i <= an; i++) {
int idx = bs(a, b, i, 1, bn);
rez = max(rez, b[idx]-i);
}
for(int i = 1; i <= bn; i++) {
int idx = bs(b, a, i, 1, an);
rez = max(rez, a[idx]-i);
}
cout << fixed << setprecision(4) << rez;
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... |