Submission #998750

# Submission time Handle Problem Language Result Execution time Memory
998750 2024-06-14T15:54:57 Z LOLOLO Gym Badges (NOI22_gymbadges) C++17
100 / 100
143 ms 22092 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (ll)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())
 
const int N = 1e6 + 10;
int x[N], l[N];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;

    for (int i = 1; i <= n; i++)
        cin >> x[i];

    vector <int> order;
    for (int i = 1; i <= n; i++) {
        cin >> l[i];
        order.pb(i);
    }

    sort(all(order), [&] (int a, int b) { return x[a] + l[a] < x[b] + l[b];});
    priority_queue <ll> pq;
    ll sum = 0;

    for (auto i : order) {
        if (sum <= l[i]) {
            sum += x[i];
            pq.push(x[i]);
        } else {
            if (pq.empty())
                continue;

            ll t = pq.top();
            if (t > x[i] && sum - t <= l[i]) {
                pq.pop();
                pq.push(x[i]);
                sum += (x[i] - t);
            }
        }
    }

    cout << sz(pq) << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 123 ms 8780 KB Output is correct
2 Correct 120 ms 8768 KB Output is correct
3 Correct 124 ms 8912 KB Output is correct
4 Correct 143 ms 8824 KB Output is correct
5 Correct 115 ms 8908 KB Output is correct
6 Correct 114 ms 9160 KB Output is correct
7 Correct 111 ms 8912 KB Output is correct
8 Correct 114 ms 8860 KB Output is correct
9 Correct 109 ms 9156 KB Output is correct
10 Correct 110 ms 9156 KB Output is correct
11 Correct 111 ms 11716 KB Output is correct
12 Correct 103 ms 14128 KB Output is correct
13 Correct 99 ms 11720 KB Output is correct
14 Correct 101 ms 12868 KB Output is correct
15 Correct 99 ms 14408 KB Output is correct
16 Correct 107 ms 10256 KB Output is correct
17 Correct 108 ms 10312 KB Output is correct
18 Correct 109 ms 10436 KB Output is correct
19 Correct 115 ms 9668 KB Output is correct
20 Correct 108 ms 9284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 2 ms 2648 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 2 ms 2652 KB Output is correct
26 Correct 1 ms 2460 KB Output is correct
27 Correct 2 ms 2608 KB Output is correct
28 Correct 2 ms 2652 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2652 KB Output is correct
31 Correct 1 ms 2684 KB Output is correct
32 Correct 2 ms 2652 KB Output is correct
33 Correct 2 ms 2604 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 2 ms 2652 KB Output is correct
36 Correct 2 ms 2652 KB Output is correct
37 Correct 2 ms 2676 KB Output is correct
38 Correct 2 ms 2648 KB Output is correct
39 Correct 2 ms 2532 KB Output is correct
40 Correct 2 ms 2520 KB Output is correct
41 Correct 1 ms 2652 KB Output is correct
42 Correct 2 ms 2652 KB Output is correct
43 Correct 2 ms 2904 KB Output is correct
44 Correct 2 ms 2652 KB Output is correct
45 Correct 1 ms 2520 KB Output is correct
46 Correct 2 ms 2652 KB Output is correct
47 Correct 2 ms 2652 KB Output is correct
48 Correct 2 ms 2652 KB Output is correct
49 Correct 2 ms 2652 KB Output is correct
50 Correct 2 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 123 ms 8780 KB Output is correct
22 Correct 120 ms 8768 KB Output is correct
23 Correct 124 ms 8912 KB Output is correct
24 Correct 143 ms 8824 KB Output is correct
25 Correct 115 ms 8908 KB Output is correct
26 Correct 114 ms 9160 KB Output is correct
27 Correct 111 ms 8912 KB Output is correct
28 Correct 114 ms 8860 KB Output is correct
29 Correct 109 ms 9156 KB Output is correct
30 Correct 110 ms 9156 KB Output is correct
31 Correct 111 ms 11716 KB Output is correct
32 Correct 103 ms 14128 KB Output is correct
33 Correct 99 ms 11720 KB Output is correct
34 Correct 101 ms 12868 KB Output is correct
35 Correct 99 ms 14408 KB Output is correct
36 Correct 107 ms 10256 KB Output is correct
37 Correct 108 ms 10312 KB Output is correct
38 Correct 109 ms 10436 KB Output is correct
39 Correct 115 ms 9668 KB Output is correct
40 Correct 108 ms 9284 KB Output is correct
41 Correct 1 ms 2392 KB Output is correct
42 Correct 2 ms 2648 KB Output is correct
43 Correct 2 ms 2652 KB Output is correct
44 Correct 1 ms 2652 KB Output is correct
45 Correct 2 ms 2652 KB Output is correct
46 Correct 1 ms 2460 KB Output is correct
47 Correct 2 ms 2608 KB Output is correct
48 Correct 2 ms 2652 KB Output is correct
49 Correct 1 ms 2652 KB Output is correct
50 Correct 1 ms 2652 KB Output is correct
51 Correct 1 ms 2684 KB Output is correct
52 Correct 2 ms 2652 KB Output is correct
53 Correct 2 ms 2604 KB Output is correct
54 Correct 1 ms 2652 KB Output is correct
55 Correct 2 ms 2652 KB Output is correct
56 Correct 2 ms 2652 KB Output is correct
57 Correct 2 ms 2676 KB Output is correct
58 Correct 2 ms 2648 KB Output is correct
59 Correct 2 ms 2532 KB Output is correct
60 Correct 2 ms 2520 KB Output is correct
61 Correct 1 ms 2652 KB Output is correct
62 Correct 2 ms 2652 KB Output is correct
63 Correct 2 ms 2904 KB Output is correct
64 Correct 2 ms 2652 KB Output is correct
65 Correct 1 ms 2520 KB Output is correct
66 Correct 2 ms 2652 KB Output is correct
67 Correct 2 ms 2652 KB Output is correct
68 Correct 2 ms 2652 KB Output is correct
69 Correct 2 ms 2652 KB Output is correct
70 Correct 2 ms 2652 KB Output is correct
71 Correct 1 ms 2392 KB Output is correct
72 Correct 0 ms 2396 KB Output is correct
73 Correct 115 ms 18124 KB Output is correct
74 Correct 118 ms 18120 KB Output is correct
75 Correct 113 ms 18124 KB Output is correct
76 Correct 122 ms 18228 KB Output is correct
77 Correct 112 ms 18212 KB Output is correct
78 Correct 118 ms 19236 KB Output is correct
79 Correct 114 ms 19396 KB Output is correct
80 Correct 121 ms 19256 KB Output is correct
81 Correct 116 ms 19404 KB Output is correct
82 Correct 118 ms 19396 KB Output is correct
83 Correct 118 ms 20220 KB Output is correct
84 Correct 116 ms 20308 KB Output is correct
85 Correct 119 ms 20136 KB Output is correct
86 Correct 123 ms 20212 KB Output is correct
87 Correct 128 ms 20212 KB Output is correct
88 Correct 118 ms 22092 KB Output is correct
89 Correct 121 ms 20808 KB Output is correct
90 Correct 126 ms 20920 KB Output is correct
91 Correct 115 ms 21576 KB Output is correct
92 Correct 118 ms 21580 KB Output is correct
93 Correct 117 ms 21320 KB Output is correct
94 Correct 117 ms 20808 KB Output is correct
95 Correct 116 ms 20552 KB Output is correct
96 Correct 116 ms 21312 KB Output is correct
97 Correct 115 ms 21044 KB Output is correct
98 Correct 114 ms 18376 KB Output is correct
99 Correct 114 ms 18372 KB Output is correct
100 Correct 116 ms 18380 KB Output is correct
101 Correct 115 ms 20780 KB Output is correct
102 Correct 110 ms 21324 KB Output is correct