답안 #498348

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
498348 2021-12-25T04:37:47 Z Nalrimet Sure Bet (CEOI17_sure) C++17
100 / 100
181 ms 6768 KB
#include <bits/stdc++.h>
using namespace std;

//#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define S second
#define F first

//const int inf = 1e18;
const int N = 100005;

int n, y;
long double a[N], b[N], pref[N], suma, ans;

ld f(int x){
//    cout << x << ' ' << y << ' ' << pref[x] << ' ' << suma << '\n';
    return min(pref[x], suma) - x - y;
}

 main(){
//	ios_base::sync_with_stdio(0);
//	cin.tie(0);
//	cout.tie(0);

    cin >> n;

    for(int i = 1; i <= n; ++i){
        cin >> a[i] >> b[i];
    }

    sort(a + 1, a + 1 + n, greater<ld>());
    sort(b + 1, b + 1 + n, greater<ld>());


    for(int i = 0; i <= n; ++i){
        pref[i] += pref[i - 1] + b[i];
    }

    for(int i = 0; i <= n; ++i){
//        cout << a[i] << ' ';
        suma += a[i];
        y = i;
//        for(int j = 0; j <= n; ++j){
//        }
        int l = 0, r = n;
//        ld = eps = 1e-9
        while(r - l > 2){
            int m1 = l + (r - l) / 3, m2 = r - (r - l) / 3;
            if(f(m1) < f(m2))
                l = m1 + 1;
            else
                r = m2 - 1;
        }
        ans = max(ans, f(l));
        if(l + 1 <= n)
            ans = max(ans, f(l + 1));
        if(l + 2 <= n)
            ans = max(ans, f(l + 2));

    }

    cout << fixed << setprecision(4) << ans;
}

Compilation message

sure.cpp:22:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   22 |  main(){
      |  ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 3 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 3 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 154 ms 4904 KB Output is correct
18 Correct 157 ms 5064 KB Output is correct
19 Correct 158 ms 4892 KB Output is correct
20 Correct 179 ms 6324 KB Output is correct
21 Correct 170 ms 6696 KB Output is correct
22 Correct 159 ms 6348 KB Output is correct
23 Correct 152 ms 6296 KB Output is correct
24 Correct 159 ms 6320 KB Output is correct
25 Correct 181 ms 6248 KB Output is correct
26 Correct 171 ms 6768 KB Output is correct