Submission #879806

# Submission time Handle Problem Language Result Execution time Memory
879806 2023-11-28T07:20:06 Z TAhmed33 Akcija (COCI21_akcija) C++
90 / 110
1697 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;
}
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; });
    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) continue;
            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 (int j = 0; j <= n; j++) dp[i + 1][j].clear();
    }
    for (auto [x, y] : dp[1][0]) cout << x << " " << y << '\n';
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:20:27: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   20 |                 for (auto [x, y] : dp[i + 1][j + 1]) {
      |                           ^
Main.cpp:25: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]
   25 |             while (dp[i][j].size() > k) dp[i][j].pop_back();
      |                    ~~~~~~~~~~~~~~~~^~~
Main.cpp:29:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   29 |     for (auto [x, y] : dp[1][0]) cout << x << " " << y << '\n';
      |               ^
# Verdict Execution time Memory Grader output
1 Correct 234 ms 240976 KB Output is correct
2 Correct 252 ms 253176 KB Output is correct
3 Correct 213 ms 228184 KB Output is correct
4 Correct 207 ms 225872 KB Output is correct
5 Correct 252 ms 250672 KB Output is correct
6 Correct 140 ms 199420 KB Output is correct
7 Correct 165 ms 220928 KB Output is correct
8 Correct 147 ms 203348 KB Output is correct
9 Correct 142 ms 198992 KB Output is correct
10 Correct 185 ms 219984 KB Output is correct
11 Correct 21 ms 96604 KB Output is correct
12 Correct 21 ms 96604 KB Output is correct
13 Correct 21 ms 96656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 234 ms 240976 KB Output is correct
2 Correct 252 ms 253176 KB Output is correct
3 Correct 213 ms 228184 KB Output is correct
4 Correct 207 ms 225872 KB Output is correct
5 Correct 252 ms 250672 KB Output is correct
6 Correct 140 ms 199420 KB Output is correct
7 Correct 165 ms 220928 KB Output is correct
8 Correct 147 ms 203348 KB Output is correct
9 Correct 142 ms 198992 KB Output is correct
10 Correct 185 ms 219984 KB Output is correct
11 Correct 21 ms 96604 KB Output is correct
12 Correct 21 ms 96604 KB Output is correct
13 Correct 21 ms 96656 KB Output is correct
14 Correct 235 ms 241196 KB Output is correct
15 Correct 247 ms 252752 KB Output is correct
16 Correct 212 ms 228196 KB Output is correct
17 Correct 215 ms 226056 KB Output is correct
18 Correct 244 ms 250448 KB Output is correct
19 Correct 140 ms 199504 KB Output is correct
20 Correct 173 ms 221136 KB Output is correct
21 Correct 160 ms 203304 KB Output is correct
22 Correct 142 ms 198992 KB Output is correct
23 Correct 183 ms 220224 KB Output is correct
24 Correct 22 ms 96604 KB Output is correct
25 Correct 21 ms 96604 KB Output is correct
26 Correct 21 ms 96620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 322 ms 327660 KB Output is correct
2 Correct 351 ms 346552 KB Output is correct
3 Correct 295 ms 306772 KB Output is correct
4 Correct 290 ms 303184 KB Output is correct
5 Correct 340 ms 342944 KB Output is correct
6 Correct 147 ms 199628 KB Output is correct
7 Correct 168 ms 221484 KB Output is correct
8 Correct 149 ms 203600 KB Output is correct
9 Correct 147 ms 200748 KB Output is correct
10 Correct 232 ms 260948 KB Output is correct
11 Correct 21 ms 96684 KB Output is correct
12 Correct 21 ms 96636 KB Output is correct
13 Correct 21 ms 96860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 101980 KB Output is correct
2 Correct 32 ms 100444 KB Output is correct
3 Correct 30 ms 99416 KB Output is correct
4 Correct 27 ms 98904 KB Output is correct
5 Correct 37 ms 102368 KB Output is correct
6 Correct 21 ms 96600 KB Output is correct
7 Correct 25 ms 97884 KB Output is correct
8 Correct 22 ms 97116 KB Output is correct
9 Correct 22 ms 97116 KB Output is correct
10 Correct 21 ms 96600 KB Output is correct
11 Correct 21 ms 96604 KB Output is correct
12 Correct 21 ms 96604 KB Output is correct
13 Correct 29 ms 99420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 115536 KB Output is correct
2 Correct 53 ms 116048 KB Output is correct
3 Correct 50 ms 112728 KB Output is correct
4 Correct 48 ms 112212 KB Output is correct
5 Correct 56 ms 117128 KB Output is correct
6 Correct 21 ms 97112 KB Output is correct
7 Correct 25 ms 98136 KB Output is correct
8 Correct 22 ms 97628 KB Output is correct
9 Correct 24 ms 98536 KB Output is correct
10 Correct 35 ms 105300 KB Output is correct
11 Correct 21 ms 96604 KB Output is correct
12 Correct 21 ms 96604 KB Output is correct
13 Correct 28 ms 100356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 234 ms 240976 KB Output is correct
2 Correct 252 ms 253176 KB Output is correct
3 Correct 213 ms 228184 KB Output is correct
4 Correct 207 ms 225872 KB Output is correct
5 Correct 252 ms 250672 KB Output is correct
6 Correct 140 ms 199420 KB Output is correct
7 Correct 165 ms 220928 KB Output is correct
8 Correct 147 ms 203348 KB Output is correct
9 Correct 142 ms 198992 KB Output is correct
10 Correct 185 ms 219984 KB Output is correct
11 Correct 21 ms 96604 KB Output is correct
12 Correct 21 ms 96604 KB Output is correct
13 Correct 21 ms 96656 KB Output is correct
14 Correct 235 ms 241196 KB Output is correct
15 Correct 247 ms 252752 KB Output is correct
16 Correct 212 ms 228196 KB Output is correct
17 Correct 215 ms 226056 KB Output is correct
18 Correct 244 ms 250448 KB Output is correct
19 Correct 140 ms 199504 KB Output is correct
20 Correct 173 ms 221136 KB Output is correct
21 Correct 160 ms 203304 KB Output is correct
22 Correct 142 ms 198992 KB Output is correct
23 Correct 183 ms 220224 KB Output is correct
24 Correct 22 ms 96604 KB Output is correct
25 Correct 21 ms 96604 KB Output is correct
26 Correct 21 ms 96620 KB Output is correct
27 Correct 322 ms 327660 KB Output is correct
28 Correct 351 ms 346552 KB Output is correct
29 Correct 295 ms 306772 KB Output is correct
30 Correct 290 ms 303184 KB Output is correct
31 Correct 340 ms 342944 KB Output is correct
32 Correct 147 ms 199628 KB Output is correct
33 Correct 168 ms 221484 KB Output is correct
34 Correct 149 ms 203600 KB Output is correct
35 Correct 147 ms 200748 KB Output is correct
36 Correct 232 ms 260948 KB Output is correct
37 Correct 21 ms 96684 KB Output is correct
38 Correct 21 ms 96636 KB Output is correct
39 Correct 21 ms 96860 KB Output is correct
40 Correct 40 ms 101980 KB Output is correct
41 Correct 32 ms 100444 KB Output is correct
42 Correct 30 ms 99416 KB Output is correct
43 Correct 27 ms 98904 KB Output is correct
44 Correct 37 ms 102368 KB Output is correct
45 Correct 21 ms 96600 KB Output is correct
46 Correct 25 ms 97884 KB Output is correct
47 Correct 22 ms 97116 KB Output is correct
48 Correct 22 ms 97116 KB Output is correct
49 Correct 21 ms 96600 KB Output is correct
50 Correct 21 ms 96604 KB Output is correct
51 Correct 21 ms 96604 KB Output is correct
52 Correct 29 ms 99420 KB Output is correct
53 Correct 55 ms 115536 KB Output is correct
54 Correct 53 ms 116048 KB Output is correct
55 Correct 50 ms 112728 KB Output is correct
56 Correct 48 ms 112212 KB Output is correct
57 Correct 56 ms 117128 KB Output is correct
58 Correct 21 ms 97112 KB Output is correct
59 Correct 25 ms 98136 KB Output is correct
60 Correct 22 ms 97628 KB Output is correct
61 Correct 24 ms 98536 KB Output is correct
62 Correct 35 ms 105300 KB Output is correct
63 Correct 21 ms 96604 KB Output is correct
64 Correct 21 ms 96604 KB Output is correct
65 Correct 28 ms 100356 KB Output is correct
66 Runtime error 1697 ms 524288 KB Execution killed with signal 9
67 Halted 0 ms 0 KB -