Submission #504126

# Submission time Handle Problem Language Result Execution time Memory
504126 2022-01-09T21:55:48 Z Hacv16 Sure Bet (CEOI17_sure) C++17
0 / 100
28 ms 716 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int MAX = 2e6 + 15;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;

#define pb push_back
#define sz(x) (int) x.size()
#define fr first
#define sc second
#define mp make_pair
#define all(x) x.begin(), x.end()

int n;
long double a[MAX], b[MAX];

void setIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 

    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin); 
        freopen("output.txt", "w", stdout);
    #endif
}

int main(){
    setIO();

    cin >> n;

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

    sort(a, a + n, greater<long double>());
    sort(b, b + n, greater<long double>());

    int pa = 1, pb = 1;
    long double sa = a[0], sb = b[0], ans = 0;

    while(pa != n && pb != n){
        if(sa < sb){
            sa += a[pa];
            pa++;
        }else{
            sb += b[pb];
            pb++;
        }

        ans = max(ans, min(sa - (pa + pb), sb - (pa + pb)));
    }
 
    cout << setprecision(4) << fixed << ans << endl;

    return 0;
}

 
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?)
    * do smth instead of nothing and stay organized
    * brute force to find pattern?
    * sort?
    * graph?
    * WRITE STUFF DOWN
    * DON'T GET STUCK ON ONE APPROACH
*/

Compilation message

sure.cpp: In function 'void setIO()':
sure.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sure.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen("output.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 28 ms 716 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 28 ms 716 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 28 ms 716 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -