Submission #848908

#TimeUsernameProblemLanguageResultExecution timeMemory
848908sandry24Sure Bet (CEOI17_sure)C++17
100 / 100
66 ms4432 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pi; #define pb push_back #define mp make_pair #define f first #define s second void solve(){ int n; cin >> n; vector<double> a(n), b(n), prefix_b(n); for(int i = 0; i < n; i++) cin >> a[i] >> b[i]; sort(a.begin(), a.end(), greater<double>()); sort(b.begin(), b.end(), greater<double>()); prefix_b[0] = b[0]; for(int i = 1; i < n; i++) prefix_b[i] = prefix_b[i-1] + b[i]; double total_a = 0, total_max = 0; for(int i = 0; i < n; i++){ total_a += a[i]; auto it = upper_bound(prefix_b.begin(), prefix_b.end(), total_a) - prefix_b.begin(); if(it != n) total_max = max(total_max, min(total_a - (i+it+2), prefix_b[it] - (i+it+2))); it--; if(it != -1) total_max = max(total_max, min(total_a - (i+it+2), prefix_b[it] - (i+it+2))); } cout << fixed << setprecision(4) << total_max << '\n'; } int main(){ //freopen("flota.in", "r", stdin); //freopen("flota.out", "w", stdout); ios::sync_with_stdio(0); cin.tie(0); int t = 1; //cin >> t; while(t--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...