답안 #108665

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
108665 2019-04-30T15:42:25 Z someone_aa Sure Bet (CEOI17_sure) C++17
100 / 100
245 ms 8652 KB
#include <bits/stdc++.h>
#define ld long double
using namespace std;
const int N = 100100;
vector<ld> a, b;
ld apref[N], bpref[N];
int n;

ld f(int a, int x) {
    return min(bpref[a]-(a+x), apref[x]-(a+x));
}

int bin_search(int x) {
    // searching in b, x
    int index = 0;
    for(int cekor = n; cekor > 0; cekor/=2) {
        while(index + cekor <= n && f(index+cekor, x)<f(index+cekor+1, x)) index+=cekor;
    }
    return index+1;
}

int main() {
    cin>>n;
    ld x, y;
    for(int i=0;i<n;i++) {
        cin>>x>>y;
        a.push_back(x);
        b.push_back(y);
    }
    sort(a.rbegin(), a.rend());
    sort(b.rbegin(), b.rend());
    for(int i=1;i<=n;i++) {
        apref[i] = apref[i-1] + a[i-1];
        bpref[i] = bpref[i-1] + b[i-1];
    }

    ld result = 0;
    for(int i=1;i<=n;i++) {
        int x = bin_search(i);
        result = max(result, min(apref[i]-(i+x), bpref[x]-(i+x)));
    }
    cout<<setprecision(4)<<fixed<<result<<"\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 6 ms 512 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 6 ms 512 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 205 ms 8180 KB Output is correct
18 Correct 186 ms 8272 KB Output is correct
19 Correct 245 ms 8408 KB Output is correct
20 Correct 176 ms 8276 KB Output is correct
21 Correct 219 ms 8652 KB Output is correct
22 Correct 181 ms 8152 KB Output is correct
23 Correct 232 ms 8236 KB Output is correct
24 Correct 185 ms 8428 KB Output is correct
25 Correct 194 ms 8236 KB Output is correct
26 Correct 203 ms 8532 KB Output is correct