Submission #880369

# Submission time Handle Problem Language Result Execution time Memory
880369 2023-11-29T08:33:14 Z TAhmed33 Akcija (COCI21_akcija) C++
90 / 110
5000 ms 40136 KB
    #include <bits/stdc++.h>
    #pragma GCC optimize ("Ofast")
    using namespace std;
    const int MAXN = 2e3 + 25;
    typedef long long ll;
    int n, k; pair <ll, ll> a[MAXN];
    vector <ll> dp[2][MAXN];
    vector <ll> merge (vector <ll> &a, vector <ll> &b, ll c) {
        vector <ll> ret;
        int p1 = 0, p2 = 0;
        while ((int)ret.size() < k && p1 < (int)a.size() && p2 < (int)b.size()) {
            if (a[p1] < b[p2] + c) {
                ret.push_back(a[p1++]);
            } else {
                ret.push_back(b[p2++] + c);
            }
        }
        while ((int)ret.size() < k && p1 < (int)a.size()) ret.push_back(a[p1++]);
        while ((int)ret.size() < k && p2 < (int)b.size()) ret.push_back(b[p2++] + c);
        return ret;
    }
    int main () {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cin >> n >> k;
        for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;
        sort(a + 1, a + n + 1, [] (pair <ll, ll> &x, pair <ll, ll> &y) { return x.second < y.second; });
        dp[0][0].push_back(0);
        for (int i = 0, c = 0; i <= n - 1; i++, c ^= 1) {
            for (int j = 0; j <= n; j++) dp[c ^ 1][j] = dp[c][j];
            for (int j = a[i + 1].second - 1; j >= 0; j--) {
                dp[c ^ 1][j + 1] = merge(dp[c ^ 1][j + 1], dp[c][j], a[i + 1].first);
            }
        }
        for (int i = n; i >= 0; i--) {
            for (auto j : dp[n & 1][i]) {
                cout << i << " " << j << '\n';
                k--;
                if (k == 0) break;
            }
            if (k == 0) break;
        }
    }
# Verdict Execution time Memory Grader output
1 Correct 53 ms 604 KB Output is correct
2 Correct 50 ms 712 KB Output is correct
3 Correct 44 ms 604 KB Output is correct
4 Correct 49 ms 1148 KB Output is correct
5 Correct 52 ms 600 KB Output is correct
6 Correct 5 ms 600 KB Output is correct
7 Correct 6 ms 604 KB Output is correct
8 Correct 5 ms 604 KB Output is correct
9 Correct 6 ms 604 KB Output is correct
10 Correct 19 ms 636 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
# Verdict Execution time Memory Grader output
1 Correct 53 ms 604 KB Output is correct
2 Correct 50 ms 712 KB Output is correct
3 Correct 44 ms 604 KB Output is correct
4 Correct 49 ms 1148 KB Output is correct
5 Correct 52 ms 600 KB Output is correct
6 Correct 5 ms 600 KB Output is correct
7 Correct 6 ms 604 KB Output is correct
8 Correct 5 ms 604 KB Output is correct
9 Correct 6 ms 604 KB Output is correct
10 Correct 19 ms 636 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 65 ms 700 KB Output is correct
15 Correct 58 ms 652 KB Output is correct
16 Correct 44 ms 696 KB Output is correct
17 Correct 45 ms 904 KB Output is correct
18 Correct 52 ms 656 KB Output is correct
19 Correct 5 ms 600 KB Output is correct
20 Correct 6 ms 604 KB Output is correct
21 Correct 5 ms 604 KB Output is correct
22 Correct 6 ms 604 KB Output is correct
23 Correct 19 ms 604 KB Output is correct
24 Correct 0 ms 552 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 808 KB Output is correct
2 Correct 93 ms 672 KB Output is correct
3 Correct 75 ms 600 KB Output is correct
4 Correct 79 ms 604 KB Output is correct
5 Correct 91 ms 600 KB Output is correct
6 Correct 5 ms 600 KB Output is correct
7 Correct 7 ms 604 KB Output is correct
8 Correct 6 ms 600 KB Output is correct
9 Correct 7 ms 604 KB Output is correct
10 Correct 27 ms 856 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 556 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 856 KB Output is correct
2 Correct 2 ms 856 KB Output is correct
3 Correct 2 ms 856 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 604 KB Output is correct
2 Correct 3 ms 604 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 604 KB Output is correct
2 Correct 50 ms 712 KB Output is correct
3 Correct 44 ms 604 KB Output is correct
4 Correct 49 ms 1148 KB Output is correct
5 Correct 52 ms 600 KB Output is correct
6 Correct 5 ms 600 KB Output is correct
7 Correct 6 ms 604 KB Output is correct
8 Correct 5 ms 604 KB Output is correct
9 Correct 6 ms 604 KB Output is correct
10 Correct 19 ms 636 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 65 ms 700 KB Output is correct
15 Correct 58 ms 652 KB Output is correct
16 Correct 44 ms 696 KB Output is correct
17 Correct 45 ms 904 KB Output is correct
18 Correct 52 ms 656 KB Output is correct
19 Correct 5 ms 600 KB Output is correct
20 Correct 6 ms 604 KB Output is correct
21 Correct 5 ms 604 KB Output is correct
22 Correct 6 ms 604 KB Output is correct
23 Correct 19 ms 604 KB Output is correct
24 Correct 0 ms 552 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 83 ms 808 KB Output is correct
28 Correct 93 ms 672 KB Output is correct
29 Correct 75 ms 600 KB Output is correct
30 Correct 79 ms 604 KB Output is correct
31 Correct 91 ms 600 KB Output is correct
32 Correct 5 ms 600 KB Output is correct
33 Correct 7 ms 604 KB Output is correct
34 Correct 6 ms 600 KB Output is correct
35 Correct 7 ms 604 KB Output is correct
36 Correct 27 ms 856 KB Output is correct
37 Correct 0 ms 344 KB Output is correct
38 Correct 0 ms 556 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 2 ms 856 KB Output is correct
41 Correct 2 ms 856 KB Output is correct
42 Correct 2 ms 856 KB Output is correct
43 Correct 1 ms 860 KB Output is correct
44 Correct 2 ms 860 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 604 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 1 ms 860 KB Output is correct
53 Correct 3 ms 604 KB Output is correct
54 Correct 3 ms 604 KB Output is correct
55 Correct 2 ms 604 KB Output is correct
56 Correct 2 ms 600 KB Output is correct
57 Correct 3 ms 604 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 1 ms 600 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 1 ms 344 KB Output is correct
62 Correct 2 ms 604 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 1 ms 600 KB Output is correct
66 Execution timed out 5027 ms 40136 KB Time limit exceeded
67 Halted 0 ms 0 KB -