Submission #422698

#TimeUsernameProblemLanguageResultExecution timeMemory
422698ak2006Sure Bet (CEOI17_sure)C++14
100 / 100
116 ms4328 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using vb = vector<bool>; using vvb = vector<vb>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using vc = vector<char>; using vvc = vector<vc>; using vs = vector<string>; const ll mod = 1e9 + 7,inf = 1e18; #define pb push_back #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); void setIO() { fast; } int main() { setIO(); int n; cin>>n; vector<double>a(n),b(n); vector<double>sums(n + 1); for (int i = 0;i<n;i++)cin>>a[i]>>b[i],a[i]--,b[i]--; sort(a.begin(),a.end()),sort(b.begin(),b.end()); for (int i = n - 1;i>=0;i--)sums[i] = b[i] + sums[i + 1]; double sum = 0; double out = 0; for (int i = n - 1;i>=0;i--){ int na = n - i; sum += a[i]; int l = 0,r = n - 1,ans = -1; while (l <= r){ int mid = (l + r)/2; if (sums[mid] - na >= sum - n + mid){ ans = mid; l = mid + 1; } else r = mid - 1; } if (ans == -1){ double val = sums[0] - na; out = max(out,val); } else { double val = sum - (n - ans); out = max(out,val); if (ans != n - 1)val = sums[ans + 1] - na; out = max(out,val); } } printf("%.4lf\n", out); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...