Submission #879804

# Submission time Handle Problem Language Result Execution time Memory
879804 2023-11-28T07:16:31 Z TAhmed33 Akcija (COCI21_akcija) C++
90 / 110
1913 ms 524288 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e3 + 25;
typedef long long ll;
int n; pair <ll, ll> a[MAXN];
vector <pair <ll, ll>> dp[MAXN][MAXN];
bool comb (pair <ll, ll> &a, pair <ll, ll> &b) {
    return a.first == b.first ? a.second < b.second : a.first > b.first;
}
vector <pair <ll, ll>> subs;
void recurse (int pos, int sze, ll cost) {
    if (pos > n) {
        subs.push_back({sze, cost});
        return;
    }
    recurse(pos + 1, sze, cost);
    if (sze + 1 <= a[pos].second) recurse(pos + 1, sze + 1, cost + a[pos].first);
}
int main () {
    cin >> n; int k; cin >> 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; });
    if (n <= 20) {
        recurse(1, 0, 0);
        sort(subs.begin(), subs.end(), comb);
        for (int i = 0; i < k; i++) {
            cout << subs[i].first << " " << subs[i].second << '\n';
        }
        return 0;
    }
    for (int j = 0; j <= n + 1; j++) dp[n + 1][j].push_back({0, 0});
    for (int i = n; i >= 1; i--) {
        for (int j = 0; j <= n; j++) {
            dp[i][j] = dp[i + 1][j];
            if (j + 1 <= a[i].second) {
                for (auto [x, y] : dp[i + 1][j + 1]) {
                    dp[i][j].push_back({x + 1, y + a[i].first});
                }
            }
            sort(dp[i][j].begin(), dp[i][j].end(), comb);
            while (dp[i][j].size() > k) dp[i][j].pop_back();
        }
    }
    for (auto [x, y] : dp[1][0]) cout << x << " " << y << '\n';
    //for (int i = 0; i < k; i++) cout << dp[1][0][i].first << " " << dp[1][0][i].second << '\n';
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:36:27: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   36 |                 for (auto [x, y] : dp[i + 1][j + 1]) {
      |                           ^
Main.cpp:41:36: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   41 |             while (dp[i][j].size() > k) dp[i][j].pop_back();
      |                    ~~~~~~~~~~~~~~~~^~~
Main.cpp:44:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   44 |     for (auto [x, y] : dp[1][0]) cout << x << " " << y << '\n';
      |               ^
# Verdict Execution time Memory Grader output
1 Correct 262 ms 240976 KB Output is correct
2 Correct 281 ms 253008 KB Output is correct
3 Correct 241 ms 228180 KB Output is correct
4 Correct 233 ms 225876 KB Output is correct
5 Correct 270 ms 250480 KB Output is correct
6 Correct 174 ms 199592 KB Output is correct
7 Correct 205 ms 221028 KB Output is correct
8 Correct 178 ms 203348 KB Output is correct
9 Correct 174 ms 199160 KB Output is correct
10 Correct 215 ms 220200 KB Output is correct
11 Correct 21 ms 96604 KB Output is correct
12 Correct 24 ms 96516 KB Output is correct
13 Correct 22 ms 96604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 262 ms 240976 KB Output is correct
2 Correct 281 ms 253008 KB Output is correct
3 Correct 241 ms 228180 KB Output is correct
4 Correct 233 ms 225876 KB Output is correct
5 Correct 270 ms 250480 KB Output is correct
6 Correct 174 ms 199592 KB Output is correct
7 Correct 205 ms 221028 KB Output is correct
8 Correct 178 ms 203348 KB Output is correct
9 Correct 174 ms 199160 KB Output is correct
10 Correct 215 ms 220200 KB Output is correct
11 Correct 21 ms 96604 KB Output is correct
12 Correct 24 ms 96516 KB Output is correct
13 Correct 22 ms 96604 KB Output is correct
14 Correct 254 ms 240980 KB Output is correct
15 Correct 280 ms 253352 KB Output is correct
16 Correct 231 ms 228180 KB Output is correct
17 Correct 236 ms 225920 KB Output is correct
18 Correct 276 ms 250752 KB Output is correct
19 Correct 173 ms 199600 KB Output is correct
20 Correct 216 ms 221012 KB Output is correct
21 Correct 179 ms 203456 KB Output is correct
22 Correct 172 ms 199068 KB Output is correct
23 Correct 214 ms 220244 KB Output is correct
24 Correct 23 ms 96700 KB Output is correct
25 Correct 21 ms 96600 KB Output is correct
26 Correct 21 ms 96604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 348 ms 327696 KB Output is correct
2 Correct 374 ms 346264 KB Output is correct
3 Correct 320 ms 307036 KB Output is correct
4 Correct 319 ms 303416 KB Output is correct
5 Correct 369 ms 342856 KB Output is correct
6 Correct 177 ms 199508 KB Output is correct
7 Correct 205 ms 221264 KB Output is correct
8 Correct 181 ms 203780 KB Output is correct
9 Correct 178 ms 200984 KB Output is correct
10 Correct 259 ms 261192 KB Output is correct
11 Correct 22 ms 96688 KB Output is correct
12 Correct 21 ms 96604 KB Output is correct
13 Correct 22 ms 96860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 94 ms 106092 KB Output is correct
2 Correct 149 ms 114788 KB Output is correct
3 Correct 54 ms 101580 KB Output is correct
4 Correct 38 ms 98684 KB Output is correct
5 Correct 130 ms 114040 KB Output is correct
6 Correct 21 ms 96600 KB Output is correct
7 Correct 24 ms 97380 KB Output is correct
8 Correct 23 ms 96860 KB Output is correct
9 Correct 22 ms 96736 KB Output is correct
10 Correct 21 ms 96604 KB Output is correct
11 Correct 21 ms 96732 KB Output is correct
12 Correct 23 ms 96604 KB Output is correct
13 Correct 50 ms 101400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 115540 KB Output is correct
2 Correct 67 ms 116052 KB Output is correct
3 Correct 57 ms 112720 KB Output is correct
4 Correct 57 ms 112212 KB Output is correct
5 Correct 68 ms 116904 KB Output is correct
6 Correct 22 ms 97040 KB Output is correct
7 Correct 25 ms 98140 KB Output is correct
8 Correct 25 ms 97904 KB Output is correct
9 Correct 25 ms 98616 KB Output is correct
10 Correct 40 ms 105552 KB Output is correct
11 Correct 21 ms 96604 KB Output is correct
12 Correct 21 ms 96504 KB Output is correct
13 Correct 30 ms 100452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 262 ms 240976 KB Output is correct
2 Correct 281 ms 253008 KB Output is correct
3 Correct 241 ms 228180 KB Output is correct
4 Correct 233 ms 225876 KB Output is correct
5 Correct 270 ms 250480 KB Output is correct
6 Correct 174 ms 199592 KB Output is correct
7 Correct 205 ms 221028 KB Output is correct
8 Correct 178 ms 203348 KB Output is correct
9 Correct 174 ms 199160 KB Output is correct
10 Correct 215 ms 220200 KB Output is correct
11 Correct 21 ms 96604 KB Output is correct
12 Correct 24 ms 96516 KB Output is correct
13 Correct 22 ms 96604 KB Output is correct
14 Correct 254 ms 240980 KB Output is correct
15 Correct 280 ms 253352 KB Output is correct
16 Correct 231 ms 228180 KB Output is correct
17 Correct 236 ms 225920 KB Output is correct
18 Correct 276 ms 250752 KB Output is correct
19 Correct 173 ms 199600 KB Output is correct
20 Correct 216 ms 221012 KB Output is correct
21 Correct 179 ms 203456 KB Output is correct
22 Correct 172 ms 199068 KB Output is correct
23 Correct 214 ms 220244 KB Output is correct
24 Correct 23 ms 96700 KB Output is correct
25 Correct 21 ms 96600 KB Output is correct
26 Correct 21 ms 96604 KB Output is correct
27 Correct 348 ms 327696 KB Output is correct
28 Correct 374 ms 346264 KB Output is correct
29 Correct 320 ms 307036 KB Output is correct
30 Correct 319 ms 303416 KB Output is correct
31 Correct 369 ms 342856 KB Output is correct
32 Correct 177 ms 199508 KB Output is correct
33 Correct 205 ms 221264 KB Output is correct
34 Correct 181 ms 203780 KB Output is correct
35 Correct 178 ms 200984 KB Output is correct
36 Correct 259 ms 261192 KB Output is correct
37 Correct 22 ms 96688 KB Output is correct
38 Correct 21 ms 96604 KB Output is correct
39 Correct 22 ms 96860 KB Output is correct
40 Correct 94 ms 106092 KB Output is correct
41 Correct 149 ms 114788 KB Output is correct
42 Correct 54 ms 101580 KB Output is correct
43 Correct 38 ms 98684 KB Output is correct
44 Correct 130 ms 114040 KB Output is correct
45 Correct 21 ms 96600 KB Output is correct
46 Correct 24 ms 97380 KB Output is correct
47 Correct 23 ms 96860 KB Output is correct
48 Correct 22 ms 96736 KB Output is correct
49 Correct 21 ms 96604 KB Output is correct
50 Correct 21 ms 96732 KB Output is correct
51 Correct 23 ms 96604 KB Output is correct
52 Correct 50 ms 101400 KB Output is correct
53 Correct 65 ms 115540 KB Output is correct
54 Correct 67 ms 116052 KB Output is correct
55 Correct 57 ms 112720 KB Output is correct
56 Correct 57 ms 112212 KB Output is correct
57 Correct 68 ms 116904 KB Output is correct
58 Correct 22 ms 97040 KB Output is correct
59 Correct 25 ms 98140 KB Output is correct
60 Correct 25 ms 97904 KB Output is correct
61 Correct 25 ms 98616 KB Output is correct
62 Correct 40 ms 105552 KB Output is correct
63 Correct 21 ms 96604 KB Output is correct
64 Correct 21 ms 96504 KB Output is correct
65 Correct 30 ms 100452 KB Output is correct
66 Runtime error 1913 ms 524288 KB Execution killed with signal 9
67 Halted 0 ms 0 KB -