Submission #835785

# Submission time Handle Problem Language Result Execution time Memory
835785 2023-08-23T19:56:14 Z elkernos Sure Bet (CEOI17_sure) C++17
100 / 100
106 ms 3616 KB
// clang-format off
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
// template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef XOX
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; }
sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
struct { template <class T> operator T() { T x; cin >> x; return x; } } in;
#define endl '\n'
#define pb emplace_back
#define vt vector
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using i64 = long long;
// #define int long long
// clang-format on

int32_t main()
{
    int n = in;
    vector<double> a(n + 1), b(n + 1);
    for(int i = 1; i <= n; i++) a[i] = in, b[i] = in;
    sort(a.begin(), a.end()), sort(b.begin(), b.end());
    reverse(a.begin() + 1, a.end()), reverse(b.begin() + 1, b.end());
    for(int i = 1; i <= n; i++) a[i] += a[i - 1], b[i] += b[i - 1];
    debug() << imie(a) imie(b);
    double ans = 0;
    for(int rep : {0 ,1}) {
        int j = 0;
        for(int i = 0; i <= n; i++) {
            // take i times a
            while(j + 1 <= n && b[j + 1] <= a[i]) j++;
            ans = max(ans, b[j] - (i + j));
        }
        swap(a, b);
    }
    cout << fixed << setprecision(4) << ans << endl;
}

Compilation message

sure.cpp: In function 'int32_t main()':
sure.cpp:48:13: warning: unused variable 'rep' [-Wunused-variable]
   48 |     for(int rep : {0 ,1}) {
      |             ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 252 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 252 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 2 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 252 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 2 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 94 ms 3224 KB Output is correct
18 Correct 94 ms 3224 KB Output is correct
19 Correct 97 ms 3132 KB Output is correct
20 Correct 95 ms 3128 KB Output is correct
21 Correct 105 ms 3512 KB Output is correct
22 Correct 94 ms 3128 KB Output is correct
23 Correct 93 ms 3124 KB Output is correct
24 Correct 94 ms 3128 KB Output is correct
25 Correct 98 ms 3128 KB Output is correct
26 Correct 106 ms 3616 KB Output is correct