Submission #229444

#TimeUsernameProblemLanguageResultExecution timeMemory
229444bharat2002Sure Bet (CEOI17_sure)C++14
0 / 100
5 ms384 KiB
#include<bits/stdc++.h> using namespace std; const int N=1e5 + 100; const int mod=1e9 + 7; #define int long long const int inf=1e18; #define pii pair<int, int> #define f first #define s second #define mp make_pair #define FOR(i, n) for(int i=1;i<=n;i++) #define TRACE(x) cerr << #x << " = " << x << endl //Trace prints the name of the variable and the value. long double a[N], b[N];int n; bool sf(long double f, long double s) { return f>s; } signed main() { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); cin>>n; for(int i=1;i<=n;i++) cin>>a[i]>>b[i]; sort(a+1, a+n+1, sf);sort(b+1, b+n+1, sf); for(int i=2;i<=n;i++) {a[i]+=a[i-1];b[i]+=b[i-1];} int i=1, j=1;a[n+1]=b[n+1]=1000000000; long double ans=0.0; while(i<n&&j<n) { ans=max(ans, min(a[i], b[j]) - i - j); while(a[i]<=b[j]&&i<n) { i++;ans=max(ans, min(a[i], b[j]) - i - j); } while(b[j]<=a[i]&&j<n) { j++;ans=max(ans, min(a[i], b[j]) - i - j); } } cout<<fixed<<setprecision(4)<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...