Submission #639827

# Submission time Handle Problem Language Result Execution time Memory
639827 2022-09-12T06:58:07 Z ghostwriter Sure Bet (CEOI17_sure) C++14
100 / 100
96 ms 6756 KB
#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

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 time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 91 ms 6348 KB Output is correct
18 Correct 92 ms 6432 KB Output is correct
19 Correct 90 ms 6352 KB Output is correct
20 Correct 89 ms 6360 KB Output is correct
21 Correct 96 ms 6688 KB Output is correct
22 Correct 90 ms 6360 KB Output is correct
23 Correct 88 ms 6348 KB Output is correct
24 Correct 89 ms 6364 KB Output is correct
25 Correct 87 ms 6348 KB Output is correct
26 Correct 94 ms 6756 KB Output is correct