Submission #278692

# Submission time Handle Problem Language Result Execution time Memory
278692 2020-08-21T16:37:53 Z BeanZ Sure Bet (CEOI17_sure) C++14
100 / 100
132 ms 5408 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define endl '\n'
const int N = 15;
long double a[100005], b[100005];
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        if (fopen("VietCT.INP", "r")){
                freopen("VietCT.INP", "r", stdin);
                freopen("VietCT.OUT", "w", stdout);
        }
        ll n;
        cin >> n;
        for (int i = 1; i <= n; i++){
                cin >> a[i] >> b[i];
        }
        sort(a + 1, a + n + 1, greater<long double>());
        sort(b + 1, b + n + 1, greater<long double>());
        ll l = 1, r = 1;
        long double sum1 = a[1], sum2 = b[1];
        long double ans = 0;
        while (true){
                ans = max(ans, min(sum1, sum2) - (long double)(l + r));
                if (sum1 <= sum2 && l < n){
                        l++;
                        sum1 += a[l];
                } else if (r < n){
                        r++;
                        sum2 += b[r];
                } else {
                        break;
                }
        }
        cout << fixed << setprecision(4) << ans;
}
/*
*/

Compilation message

sure.cpp: In function 'int main()':
sure.cpp:13:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   13 |                 freopen("VietCT.INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
sure.cpp:14:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   14 |                 freopen("VietCT.OUT", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 115 ms 4984 KB Output is correct
18 Correct 102 ms 4856 KB Output is correct
19 Correct 107 ms 4832 KB Output is correct
20 Correct 103 ms 4860 KB Output is correct
21 Correct 116 ms 5408 KB Output is correct
22 Correct 102 ms 4856 KB Output is correct
23 Correct 103 ms 4856 KB Output is correct
24 Correct 116 ms 4856 KB Output is correct
25 Correct 124 ms 4984 KB Output is correct
26 Correct 132 ms 5240 KB Output is correct