Submission #969121

# Submission time Handle Problem Language Result Execution time Memory
969121 2024-04-24T14:18:44 Z TrendBattles Gym Badges (NOI22_gymbadges) C++14
51 / 100
2000 ms 19520 KB
//https://oj.uz/problem/view/NOI22_gymbadges
#include <bits/stdc++.h>
using namespace std;
using lli = int64_t;

#define INFILE "NOI22_gymbadges.inp"
#define OUTFILE "NOI22_gymbadges.out"
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    if (fopen(INFILE, "r")) {
        freopen(INFILE, "r", stdin);
        freopen(OUTFILE, "w", stdout);
    }
    
    int N; cin >> N;
    vector <int> X(N), L(N);
    for (int& v : X) cin >> v;
    for (int& v : L) cin >> v;

    if (*max_element(L.begin(), L.end()) == *min_element(L.begin(), L.end())) {
        sort(X.begin(), X.end());

        int ans = N;
        lli sum = 0;
        for (int i = 0; i < N; ++i) {
            if (sum > L[0]) {
                ans = i; break;
            }
            sum += X[i];
        }
        cout << ans;
        return 0;
    }

    vector <int> order(N); iota(order.begin(), order.end(), 0);
    sort(order.begin(), order.end(), [&] (int u, int v) {
        return X[u] + L[u] < X[v] + L[v];
    });

    // for (int i = 0; i < N; ++i) cerr << order[i] << ' ';
    // cerr << '\n';
    // for (int i = 0; i < N; ++i) cerr << X[order[i]] << ' ';
    // cerr << '\n';
    // for (int i = 0; i < N; ++i) cerr << L[order[i]] << ' ';
    // cerr << '\n';

    const lli inf = 0x3f3f3f3f3f3f3f3f;
    vector <lli> dp(N + 1, inf);

    dp[0] = 0;

    for (int i = 0; i < N; ++i) {
        for (int j = N; j; --j) {
            if (dp[j - 1] <= L[order[i]]) {
                dp[j] = min(dp[j], dp[j - 1] + X[order[i]]);
            }
        }

        // cerr << "DEBUG: " << i << '\n';
        // for (int j = 1; j <= N; ++j) {
        //     if (dp[j] == inf) cerr << "-1 ";
        //     else cerr << dp[j] << ' ';
        // }
        // cerr << '\n';
    }


    for (int i = N; i >= 0; --i) {
        if (dp[i] < inf) {
            cout << i; return 0;
        }
    }
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:11:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |         freopen(INFILE, "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:12:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         freopen(OUTFILE, "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 456 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 106 ms 4356 KB Output is correct
2 Correct 109 ms 4352 KB Output is correct
3 Correct 112 ms 4360 KB Output is correct
4 Correct 128 ms 4184 KB Output is correct
5 Correct 107 ms 4188 KB Output is correct
6 Correct 102 ms 4188 KB Output is correct
7 Correct 103 ms 4436 KB Output is correct
8 Correct 102 ms 4188 KB Output is correct
9 Correct 100 ms 4352 KB Output is correct
10 Correct 100 ms 4188 KB Output is correct
11 Correct 91 ms 4188 KB Output is correct
12 Correct 116 ms 4360 KB Output is correct
13 Correct 90 ms 4184 KB Output is correct
14 Correct 91 ms 4364 KB Output is correct
15 Correct 94 ms 4184 KB Output is correct
16 Correct 99 ms 4188 KB Output is correct
17 Correct 99 ms 4352 KB Output is correct
18 Correct 116 ms 4364 KB Output is correct
19 Correct 98 ms 4356 KB Output is correct
20 Correct 98 ms 4184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 456 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 17 ms 604 KB Output is correct
22 Correct 17 ms 604 KB Output is correct
23 Correct 17 ms 604 KB Output is correct
24 Correct 17 ms 600 KB Output is correct
25 Correct 17 ms 644 KB Output is correct
26 Correct 19 ms 600 KB Output is correct
27 Correct 17 ms 604 KB Output is correct
28 Correct 17 ms 604 KB Output is correct
29 Correct 25 ms 604 KB Output is correct
30 Correct 18 ms 604 KB Output is correct
31 Correct 18 ms 840 KB Output is correct
32 Correct 18 ms 860 KB Output is correct
33 Correct 18 ms 604 KB Output is correct
34 Correct 18 ms 644 KB Output is correct
35 Correct 18 ms 604 KB Output is correct
36 Correct 24 ms 604 KB Output is correct
37 Correct 22 ms 604 KB Output is correct
38 Correct 18 ms 604 KB Output is correct
39 Correct 18 ms 600 KB Output is correct
40 Correct 18 ms 604 KB Output is correct
41 Correct 19 ms 604 KB Output is correct
42 Correct 22 ms 860 KB Output is correct
43 Correct 19 ms 580 KB Output is correct
44 Correct 19 ms 604 KB Output is correct
45 Correct 20 ms 600 KB Output is correct
46 Correct 20 ms 604 KB Output is correct
47 Correct 20 ms 604 KB Output is correct
48 Correct 20 ms 604 KB Output is correct
49 Correct 21 ms 604 KB Output is correct
50 Correct 21 ms 624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 456 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 106 ms 4356 KB Output is correct
22 Correct 109 ms 4352 KB Output is correct
23 Correct 112 ms 4360 KB Output is correct
24 Correct 128 ms 4184 KB Output is correct
25 Correct 107 ms 4188 KB Output is correct
26 Correct 102 ms 4188 KB Output is correct
27 Correct 103 ms 4436 KB Output is correct
28 Correct 102 ms 4188 KB Output is correct
29 Correct 100 ms 4352 KB Output is correct
30 Correct 100 ms 4188 KB Output is correct
31 Correct 91 ms 4188 KB Output is correct
32 Correct 116 ms 4360 KB Output is correct
33 Correct 90 ms 4184 KB Output is correct
34 Correct 91 ms 4364 KB Output is correct
35 Correct 94 ms 4184 KB Output is correct
36 Correct 99 ms 4188 KB Output is correct
37 Correct 99 ms 4352 KB Output is correct
38 Correct 116 ms 4364 KB Output is correct
39 Correct 98 ms 4356 KB Output is correct
40 Correct 98 ms 4184 KB Output is correct
41 Correct 17 ms 604 KB Output is correct
42 Correct 17 ms 604 KB Output is correct
43 Correct 17 ms 604 KB Output is correct
44 Correct 17 ms 600 KB Output is correct
45 Correct 17 ms 644 KB Output is correct
46 Correct 19 ms 600 KB Output is correct
47 Correct 17 ms 604 KB Output is correct
48 Correct 17 ms 604 KB Output is correct
49 Correct 25 ms 604 KB Output is correct
50 Correct 18 ms 604 KB Output is correct
51 Correct 18 ms 840 KB Output is correct
52 Correct 18 ms 860 KB Output is correct
53 Correct 18 ms 604 KB Output is correct
54 Correct 18 ms 644 KB Output is correct
55 Correct 18 ms 604 KB Output is correct
56 Correct 24 ms 604 KB Output is correct
57 Correct 22 ms 604 KB Output is correct
58 Correct 18 ms 604 KB Output is correct
59 Correct 18 ms 600 KB Output is correct
60 Correct 18 ms 604 KB Output is correct
61 Correct 19 ms 604 KB Output is correct
62 Correct 22 ms 860 KB Output is correct
63 Correct 19 ms 580 KB Output is correct
64 Correct 19 ms 604 KB Output is correct
65 Correct 20 ms 600 KB Output is correct
66 Correct 20 ms 604 KB Output is correct
67 Correct 20 ms 604 KB Output is correct
68 Correct 20 ms 604 KB Output is correct
69 Correct 21 ms 604 KB Output is correct
70 Correct 21 ms 624 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Execution timed out 2080 ms 19520 KB Time limit exceeded
74 Halted 0 ms 0 KB -