Submission #843465

# Submission time Handle Problem Language Result Execution time Memory
843465 2023-09-04T03:09:09 Z vjudge1 Sure Bet (CEOI17_sure) C++17
0 / 100
2 ms 2396 KB
 ///***LTT***///
/// ->TUYEN QUOC GIA<- ///
#include<bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("popcnt")
//#define int long long
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define CHECKBIT(mask,i) ((mask>>(i) )&1) // == 1 la bat, == 0 la tat
#define OFFBIT(mask,i) ((1<<(i))^mask) // tat bit thu i
#define ONBIT(mask,i) ((1<<(i))mask) // bat bit thu i
using namespace std;
const long long oo = 1e9+7;
const int N = 2 * 1e5 + 10;
int n;
long double  a[N], b[N], L, R, cntl, cntr, ans;
bool cmp (long double a,long double b){
    return a > b;
}
void inp(){
    cin >> n;
    for (int i = 1;i <= n;i++){
        cin >> a[i] >> b[i];
    }
    return;
}
void solve(){
    sort(a+1,a+n+1,cmp);
    sort(b+1,b+n+1,cmp);
    int l = 1, r = 1;
    while (l <= n or r <= n){
        if (a[l] <= 1){
            l++;
        }
        if (b[r] <= 1){
            r++;
        }
        bool ok = false;
        if (L - (cntl + cntr) < R - ( cntl + cntr)){
            if (L + a[l] - (cntl + cntr + 1) > L - (cntl + cntr)){
                cntl++;
                L += a[l];
                ++l;
                ok = true;
            }
        }
        if (L - (cntl + cntr) > R - ( cntl + cntr)){
            if (R + b[l] - (cntl + cntr + 1) > R - (cntl + cntr)){
                cntr++;
                R += b[r];
                ++r;
                ok = true;
            }
        }
        if (L - (cntl + cntr) == R - ( cntl + cntr)){
                cntl++;
                L += a[l];
                ++l;
                cntr++;
                R += b[r];
                ++r;
                ok = true;
        }
        ans = max(ans, min(L - (cntl + cntr),R - ( cntl + cntr) ) );
        if (!ok) break;
    }
    cout << fixed << setprecision(4) << ans;
    return;
}
int main(){
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    if (fopen("file.inp", "r")){
        freopen("file.inp", "r", stdin);
        freopen("file.out", "w", stdout);
    }
    //int t;
    //cin >> t;
    //while(t--){
    inp();
    solve();
    //}
}



Compilation message

sure.cpp: In function 'int main()':
sure.cpp:78:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |         freopen("file.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sure.cpp:79:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |         freopen("file.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 2 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 2 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 2 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -