Submission #570757

#TimeUsernameProblemLanguageResultExecution timeMemory
570757Doanxem99Sure Bet (CEOI17_sure)C++14
100 / 100
97 ms3780 KiB
#include <bits/stdc++.h> using namespace std; #define ar array< int , 2> #define MASK(i) (1 << (i)) #define BIT(x, i) (((x) >> (i)) & 1) const int MAX = 1e5 + 1000; double n, a[MAX], b[MAX], ans, x, y; bool Compare(double a, double b) { return a >= b; } vector< double > A, B; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; A.push_back(LONG_MAX); B.push_back(LONG_MAX); for (int i = 1; i <= n; i++) { cin >> a[i] >> b[i]; A.push_back(a[i]); B.push_back(b[i]); } sort(A.begin(), A.end(), Compare); sort(B.begin(), B.end(), Compare); //for (double i : A) cout << i << '\n' ; double sum1 = A[1], sum2 = B[1], sum3 = 2.0; int i1 = 2, i2 = 2; while (true) { ans = max(ans, min(sum1 - sum3, sum2 - sum3)); if (sum1 - sum3 < 0 && i1 <= n) { sum1 += A[i1]; i1++; sum3 += 1.0; } else if (sum2 - sum3 < 0 && i2 <= n) { sum2 += B[i2]; i2++; sum3 += 1.0; } else if (sum1 < sum2 && i1 <= n) { sum1 += A[i1]; i1++; sum3 += 1.0; } else if (sum1 > sum2 && i2 <= n) { sum2 += B[i2]; i2++; sum3 += 1.0; } else if (sum1 == sum2 && i1 <= n && i2 <= n) { sum1 += A[i1]; i1++; sum3 += 1.0; sum2 += B[i2]; i2++; sum3 += 1.0; } else break; } printf("%.4lf",(double)ans); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...