Submission #639827

#TimeUsernameProblemLanguageResultExecution timeMemory
639827ghostwriterSure Bet (CEOI17_sure)C++14
100 / 100
96 ms6756 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include <debug.h> #endif #define st first #define nd second #define pb push_back #define pf push_front #define _pb pop_back #define _pf pop_front #define lb lower_bound #define ub upper_bound #define mtp make_tuple #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ldb; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll; typedef string str; template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); } template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i)) #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i)) #define EACH(i, x) for (auto &(i) : (x)) #define WHILE while #define file "TEST" mt19937 rd(chrono::steady_clock::now().time_since_epoch().count()); ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); } /* Tran The Bao CTL - Da Lat Cay ngay cay dem nhung deo duoc cong nhan */ const int N = 1e5 + 5; int n; ldb a[N], b[N], f[N], rs = 0, sum = 0; signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); // freopen(file".inp", "r", stdin); // freopen(file".out", "w", stdout); cin >> n; FOR(i, 1, n) cin >> a[i] >> b[i]; sort(a + 1, a + 1 + n, greater<ldb>()); sort(b + 1, b + 1 + n, greater<ldb>()); FOR(i, 1, n) f[i] = f[i - 1] + b[i]; FOR(i, 0, n) { sum += a[i]; int l = 0, r = n; WHILE(l <= r) { int mid = l + (r - l) / 2; ldb p1 = sum - i - mid, p2 = f[mid] - i - mid; rs = max(rs, min(p1, p2)); if (p2 < p1) l = mid + 1; else r = mid - 1; } } cout << setprecision(4) << fixed << rs; return 0; }

Compilation message (stderr)

sure.cpp: In function 'int main()':
sure.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
sure.cpp:44:5: note: in expansion of macro 'FOR'
   44 |     FOR(i, 1, n) cin >> a[i] >> b[i];
      |     ^~~
sure.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
sure.cpp:47:5: note: in expansion of macro 'FOR'
   47 |     FOR(i, 1, n) f[i] = f[i - 1] + b[i];
      |     ^~~
sure.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
sure.cpp:48:5: note: in expansion of macro 'FOR'
   48 |     FOR(i, 0, n) {
      |     ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...