Submission #1110295

# Submission time Handle Problem Language Result Execution time Memory
1110295 2024-11-09T06:47:16 Z JeffLegendPower Gym Badges (NOI22_gymbadges) C++17
100 / 100
143 ms 22472 KB
// https://oj.uz/problem/view/NOI22_gymbadges

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define plli pair<ll, int>
#define pll pair<ll, ll>
#define pii pair<int, int>
// Usage: FOR(i, 0, N) {...}
#define FOR(i, start, end) for(int i = start; i < end; i++)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int uid(int a, int b) { return uniform_int_distribution<int>(a, b)(rng); }
ll uld(ll a, ll b) { return uniform_int_distribution<ll>(a, b)(rng); }

void setIO(string s) {
	freopen((s + ".in").c_str(), "r", stdin);
	freopen((s + ".out").c_str(), "w", stdout);
}

struct comp {
    bool operator() (const plli& a, const plli& b) const {
        return a < b;
    }
};

typedef tree<plli, null_type, comp, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;


// Segtree start
const int Nmax = 1e5;  // limit for array size
int N;  // array size
int t[2 * Nmax];

int oper(int a, int b) {
    return a + b;
}

void build() {  // build the tree
  for (int i = N - 1; i > 0; --i) t[i] = oper(t[i<<1], t[i<<1|1]);
}

void modify(int p, int value) {  // set value at position p
  for (t[p += N] = value; p > 1; p >>= 1) t[p>>1] = oper(t[p], t[p^1]);
}

int query(int l, int r) {  // on interval [l, r)
  int res = 0;
  for (l += N, r += N; l < r; l >>= 1, r >>= 1) {
    if (l&1) res = oper(res, t[l++]);
    if (r&1) res = oper(res, t[--r]);
  }
  return res;
}
// Segtree end


int main() {
    // Comment out for interactive problems
    ios::sync_with_stdio(false);
	cin.tie(nullptr);
    
    int N; cin >> N;

    pll gyms[N];
    for (int i = 0; i < N; i++) cin >> gyms[i].first;
    for (int i = 0; i < N; i++) cin >> gyms[i].second;

    // sort such that at worst going thru gym i<j will result in a lower lvl than going through gym j>i
    sort(gyms, gyms + N, [](pll one, pll two) {
        return (one.first + one.second) < (two.first + two.second);
    });

    int num = 0;
    ll lvl = 0;
    priority_queue<ll> used;
    for (auto [X, L] : gyms) {
        if (lvl <= L) {
            lvl += X;
            num++;
            used.push(X);
        }

        // if cant increase # gyms, then minimize lvl
        else if (!used.empty() && used.top() > X) {
            lvl -= used.top();
            lvl += X;

            used.pop();
            used.push(X);
        }
    }

    cout << num;
}

Compilation message

Main.cpp: In function 'void setIO(std::string)':
Main.cpp:22:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |  freopen((s + ".in").c_str(), "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:23:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |  freopen((s + ".out").c_str(), "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 472 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 480 KB Output is correct
11 Correct 1 ms 504 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 124 ms 17356 KB Output is correct
2 Correct 112 ms 17616 KB Output is correct
3 Correct 119 ms 17480 KB Output is correct
4 Correct 121 ms 17488 KB Output is correct
5 Correct 117 ms 17480 KB Output is correct
6 Correct 119 ms 16736 KB Output is correct
7 Correct 108 ms 16088 KB Output is correct
8 Correct 109 ms 16712 KB Output is correct
9 Correct 121 ms 16716 KB Output is correct
10 Correct 108 ms 16844 KB Output is correct
11 Correct 101 ms 18628 KB Output is correct
12 Correct 100 ms 21696 KB Output is correct
13 Correct 98 ms 18636 KB Output is correct
14 Correct 107 ms 21696 KB Output is correct
15 Correct 101 ms 21708 KB Output is correct
16 Correct 114 ms 16992 KB Output is correct
17 Correct 121 ms 17224 KB Output is correct
18 Correct 104 ms 17096 KB Output is correct
19 Correct 105 ms 16588 KB Output is correct
20 Correct 112 ms 16588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 472 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 480 KB Output is correct
11 Correct 1 ms 504 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 2 ms 592 KB Output is correct
22 Correct 2 ms 592 KB Output is correct
23 Correct 2 ms 492 KB Output is correct
24 Correct 2 ms 760 KB Output is correct
25 Correct 2 ms 592 KB Output is correct
26 Correct 2 ms 592 KB Output is correct
27 Correct 2 ms 632 KB Output is correct
28 Correct 2 ms 760 KB Output is correct
29 Correct 2 ms 592 KB Output is correct
30 Correct 2 ms 764 KB Output is correct
31 Correct 2 ms 592 KB Output is correct
32 Correct 2 ms 592 KB Output is correct
33 Correct 2 ms 592 KB Output is correct
34 Correct 2 ms 592 KB Output is correct
35 Correct 2 ms 592 KB Output is correct
36 Correct 2 ms 592 KB Output is correct
37 Correct 2 ms 592 KB Output is correct
38 Correct 2 ms 592 KB Output is correct
39 Correct 2 ms 592 KB Output is correct
40 Correct 2 ms 764 KB Output is correct
41 Correct 2 ms 656 KB Output is correct
42 Correct 2 ms 592 KB Output is correct
43 Correct 2 ms 592 KB Output is correct
44 Correct 2 ms 592 KB Output is correct
45 Correct 2 ms 592 KB Output is correct
46 Correct 2 ms 592 KB Output is correct
47 Correct 2 ms 592 KB Output is correct
48 Correct 2 ms 592 KB Output is correct
49 Correct 2 ms 592 KB Output is correct
50 Correct 2 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 472 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 480 KB Output is correct
11 Correct 1 ms 504 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 124 ms 17356 KB Output is correct
22 Correct 112 ms 17616 KB Output is correct
23 Correct 119 ms 17480 KB Output is correct
24 Correct 121 ms 17488 KB Output is correct
25 Correct 117 ms 17480 KB Output is correct
26 Correct 119 ms 16736 KB Output is correct
27 Correct 108 ms 16088 KB Output is correct
28 Correct 109 ms 16712 KB Output is correct
29 Correct 121 ms 16716 KB Output is correct
30 Correct 108 ms 16844 KB Output is correct
31 Correct 101 ms 18628 KB Output is correct
32 Correct 100 ms 21696 KB Output is correct
33 Correct 98 ms 18636 KB Output is correct
34 Correct 107 ms 21696 KB Output is correct
35 Correct 101 ms 21708 KB Output is correct
36 Correct 114 ms 16992 KB Output is correct
37 Correct 121 ms 17224 KB Output is correct
38 Correct 104 ms 17096 KB Output is correct
39 Correct 105 ms 16588 KB Output is correct
40 Correct 112 ms 16588 KB Output is correct
41 Correct 2 ms 592 KB Output is correct
42 Correct 2 ms 592 KB Output is correct
43 Correct 2 ms 492 KB Output is correct
44 Correct 2 ms 760 KB Output is correct
45 Correct 2 ms 592 KB Output is correct
46 Correct 2 ms 592 KB Output is correct
47 Correct 2 ms 632 KB Output is correct
48 Correct 2 ms 760 KB Output is correct
49 Correct 2 ms 592 KB Output is correct
50 Correct 2 ms 764 KB Output is correct
51 Correct 2 ms 592 KB Output is correct
52 Correct 2 ms 592 KB Output is correct
53 Correct 2 ms 592 KB Output is correct
54 Correct 2 ms 592 KB Output is correct
55 Correct 2 ms 592 KB Output is correct
56 Correct 2 ms 592 KB Output is correct
57 Correct 2 ms 592 KB Output is correct
58 Correct 2 ms 592 KB Output is correct
59 Correct 2 ms 592 KB Output is correct
60 Correct 2 ms 764 KB Output is correct
61 Correct 2 ms 656 KB Output is correct
62 Correct 2 ms 592 KB Output is correct
63 Correct 2 ms 592 KB Output is correct
64 Correct 2 ms 592 KB Output is correct
65 Correct 2 ms 592 KB Output is correct
66 Correct 2 ms 592 KB Output is correct
67 Correct 2 ms 592 KB Output is correct
68 Correct 2 ms 592 KB Output is correct
69 Correct 2 ms 592 KB Output is correct
70 Correct 2 ms 592 KB Output is correct
71 Correct 1 ms 336 KB Output is correct
72 Correct 1 ms 336 KB Output is correct
73 Correct 110 ms 17544 KB Output is correct
74 Correct 127 ms 17744 KB Output is correct
75 Correct 111 ms 17640 KB Output is correct
76 Correct 111 ms 17772 KB Output is correct
77 Correct 107 ms 17740 KB Output is correct
78 Correct 121 ms 18376 KB Output is correct
79 Correct 123 ms 18520 KB Output is correct
80 Correct 116 ms 18384 KB Output is correct
81 Correct 115 ms 18376 KB Output is correct
82 Correct 112 ms 18376 KB Output is correct
83 Correct 125 ms 20044 KB Output is correct
84 Correct 113 ms 19908 KB Output is correct
85 Correct 119 ms 19916 KB Output is correct
86 Correct 120 ms 19920 KB Output is correct
87 Correct 116 ms 19792 KB Output is correct
88 Correct 118 ms 22352 KB Output is correct
89 Correct 113 ms 22464 KB Output is correct
90 Correct 119 ms 22348 KB Output is correct
91 Correct 143 ms 22464 KB Output is correct
92 Correct 111 ms 22472 KB Output is correct
93 Correct 115 ms 22100 KB Output is correct
94 Correct 110 ms 21952 KB Output is correct
95 Correct 109 ms 21952 KB Output is correct
96 Correct 121 ms 21952 KB Output is correct
97 Correct 110 ms 22092 KB Output is correct
98 Correct 117 ms 17992 KB Output is correct
99 Correct 126 ms 18008 KB Output is correct
100 Correct 115 ms 17892 KB Output is correct
101 Correct 109 ms 21440 KB Output is correct
102 Correct 113 ms 21440 KB Output is correct