답안 #282516

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
282516 2020-08-24T13:44:20 Z imeimi2000 Shopping Plans (CCO20_day2problem3) C++17
25 / 25
495 ms 56932 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long llong;

struct node {
    llong val;
    int idx, cnt;
    int movC, movL, movR, movV, movP;
    bool operator<(const node &p) const {
        return val > p.val;
    }
};

int n, m, k;
void fail() {
    while (k--) printf("-1\n");
    exit(0);
}

vector<int> C[200001];
vector<llong> G[200001];
int X[200001], Y[200001];
int main() {
    #ifdef imeimi
    //freopen("oi/cco20/6.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m >> k;
    for (int i = 1; i <= n; ++i) {
        int a, c;
        cin >> a >> c;
        C[a].push_back(c);
    }
    priority_queue<node> pq;
    llong sum = 0;
    for (int i = 1; i <= m; ++i) {
        cin >> X[i] >> Y[i];
        Y[i] = min(Y[i], int(C[i].size()));
        if (X[i] > Y[i]) fail();
        sort(C[i].begin(), C[i].end());
        vector<llong> S(C[i].size() + 1, 0);
        for (int j = 1; j < int(S.size()); ++j) {
            S[j] = S[j - 1] + C[i][j - 1];
        }
        pq.push({ 0, i, X[i], 0, 0, 0, 0, 0 });
        sum += S[X[i]];
    }
    for (int i = 0; i < m + k + 5 && !pq.empty(); ++i) {
        node n = pq.top(); pq.pop();
        G[n.idx].push_back(n.val);
        if (!n.movC && n.cnt < Y[n.idx]) {
            pq.push({ n.val + C[n.idx][n.cnt], n.idx, n.cnt + 1, 0, 0, 0, 0, 0 });
        }
        if (!n.movL && 0 <= n.cnt - n.movC - 1 && n.cnt + n.movC < int(C[n.idx].size())) {
            pq.push({ n.val - C[n.idx][n.cnt - n.movC - 1] + C[n.idx][n.cnt + n.movC], n.idx, n.cnt, n.movC + 1, 0, 0, 0, 0 });
        }
        if (!n.movL && n.movC && 0 <= n.cnt - n.movC - 1) {
            pq.push({ n.val - C[n.idx][n.cnt - n.movC - 1] + C[n.idx][n.cnt - n.movC], n.idx, n.cnt, n.movC, 1, 0, n.cnt - n.movC - 1, -1 });
        }
        if (!n.movR && n.movC && n.cnt + n.movC < int(C[n.idx].size())) {
            pq.push({ n.val - C[n.idx][n.cnt + n.movC - 1] + C[n.idx][n.cnt + n.movC], n.idx, n.cnt, n.movC, n.movC + 1, 1, n.cnt + n.movC, int(C[n.idx].size()) });
        }
        if (n.movL && n.movL <= n.movC && n.movP < n.movV - 1) {
            pq.push({ n.val - C[n.idx][n.movV - 1] + C[n.idx][n.movV], n.idx, n.cnt, n.movC, n.movL, 0, n.movV - 1, n.movP });
        }
        if (n.movL && n.movL < n.movC && n.movV < n.cnt - n.movC + n.movL - 1) {
            pq.push({ n.val - C[n.idx][n.cnt - n.movC + n.movL - 1] + C[n.idx][n.cnt - n.movC + n.movL], n.idx, n.cnt, n.movC, n.movL + 1, 0, n.cnt - n.movC + n.movL - 1, n.movV });
        }
        if (n.movR && n.movR <= n.movC && n.movV + 1 < n.movP) {
            pq.push({ n.val - C[n.idx][n.movV] + C[n.idx][n.movV + 1], n.idx, n.cnt, n.movC, n.movC + 1, n.movR, n.movV + 1, n.movP });
        }
        if (n.movR && n.movR < n.movC && n.cnt + n.movC - n.movR < n.movV) {
            pq.push({ n.val - C[n.idx][n.cnt + n.movC - n.movR - 1] + C[n.idx][n.cnt + n.movC - n.movR], n.idx, n.cnt, n.movC, n.movC + 1, n.movR + 1, n.cnt + n.movC - n.movR, n.movV });
        }
    }
    --k, printf("%lld\n", sum);
    vector<vector<llong>> g;
    for (int i = 1; i <= m; ++i) {
        if (int(G[i].size()) <= 1) continue;
        for (int j = int(G[i].size()) - 1; j > 0; --j) G[i][j] -= G[i][j - 1];
        g.push_back(G[i]);
    }
    sort(g.begin(), g.end());
    priority_queue<pair<llong, pair<int, int>>> pq2;
    if (!g.empty()) pq2.emplace(-g[0][1], pair(0, 1));
    while (k && !pq2.empty()) {
        auto tp = pq2.top(); pq2.pop();
        --k, printf("%lld\n", sum - tp.first);
        auto [idx, cnt] = tp.second;
        if (idx + 1 < int(g.size()) && cnt == 1) {
            pq2.emplace(tp.first - g[idx + 1][1] + g[idx][1], pair(idx + 1, 1));
        }
        if (idx + 1 < int(g.size())) {
            pq2.emplace(tp.first - g[idx + 1][1], pair(idx + 1, 1));
        }
        if (cnt + 1 < int(g[idx].size())) {
            pq2.emplace(tp.first - g[idx][cnt + 1], pair(idx, cnt + 1));
        }
    }
    fail();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 10464 KB Output is correct
2 Correct 10 ms 10368 KB Output is correct
3 Correct 10 ms 10368 KB Output is correct
4 Correct 9 ms 10368 KB Output is correct
5 Correct 11 ms 10464 KB Output is correct
6 Correct 10 ms 10368 KB Output is correct
7 Correct 10 ms 10240 KB Output is correct
8 Correct 9 ms 10112 KB Output is correct
9 Correct 8 ms 9984 KB Output is correct
10 Correct 9 ms 10368 KB Output is correct
11 Correct 7 ms 9856 KB Output is correct
12 Correct 7 ms 9856 KB Output is correct
13 Correct 8 ms 9984 KB Output is correct
14 Correct 12 ms 10440 KB Output is correct
15 Correct 7 ms 9856 KB Output is correct
16 Correct 8 ms 9984 KB Output is correct
17 Correct 10 ms 10368 KB Output is correct
18 Correct 8 ms 9856 KB Output is correct
19 Correct 8 ms 10112 KB Output is correct
20 Correct 10 ms 10464 KB Output is correct
21 Correct 7 ms 9856 KB Output is correct
22 Correct 8 ms 9984 KB Output is correct
23 Correct 10 ms 10112 KB Output is correct
24 Correct 9 ms 10112 KB Output is correct
25 Correct 12 ms 9984 KB Output is correct
26 Correct 10 ms 10368 KB Output is correct
27 Correct 10 ms 10240 KB Output is correct
28 Correct 10 ms 10112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 19800 KB Output is correct
2 Correct 85 ms 19552 KB Output is correct
3 Correct 81 ms 19680 KB Output is correct
4 Correct 80 ms 19552 KB Output is correct
5 Correct 74 ms 15832 KB Output is correct
6 Correct 78 ms 15764 KB Output is correct
7 Correct 80 ms 19296 KB Output is correct
8 Correct 76 ms 19176 KB Output is correct
9 Correct 16 ms 10496 KB Output is correct
10 Correct 82 ms 19804 KB Output is correct
11 Correct 16 ms 10496 KB Output is correct
12 Correct 40 ms 11132 KB Output is correct
13 Correct 91 ms 19168 KB Output is correct
14 Correct 85 ms 19680 KB Output is correct
15 Correct 17 ms 10368 KB Output is correct
16 Correct 81 ms 19164 KB Output is correct
17 Correct 100 ms 19424 KB Output is correct
18 Correct 28 ms 10872 KB Output is correct
19 Correct 83 ms 19424 KB Output is correct
20 Correct 84 ms 20052 KB Output is correct
21 Correct 18 ms 10496 KB Output is correct
22 Correct 79 ms 14572 KB Output is correct
23 Correct 75 ms 18920 KB Output is correct
24 Correct 16 ms 10528 KB Output is correct
25 Correct 16 ms 10528 KB Output is correct
26 Correct 80 ms 15460 KB Output is correct
27 Correct 82 ms 15460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 10464 KB Output is correct
2 Correct 10 ms 10368 KB Output is correct
3 Correct 10 ms 10368 KB Output is correct
4 Correct 9 ms 10368 KB Output is correct
5 Correct 11 ms 10464 KB Output is correct
6 Correct 10 ms 10368 KB Output is correct
7 Correct 10 ms 10240 KB Output is correct
8 Correct 9 ms 10112 KB Output is correct
9 Correct 8 ms 9984 KB Output is correct
10 Correct 9 ms 10368 KB Output is correct
11 Correct 7 ms 9856 KB Output is correct
12 Correct 7 ms 9856 KB Output is correct
13 Correct 8 ms 9984 KB Output is correct
14 Correct 12 ms 10440 KB Output is correct
15 Correct 7 ms 9856 KB Output is correct
16 Correct 8 ms 9984 KB Output is correct
17 Correct 10 ms 10368 KB Output is correct
18 Correct 8 ms 9856 KB Output is correct
19 Correct 8 ms 10112 KB Output is correct
20 Correct 10 ms 10464 KB Output is correct
21 Correct 7 ms 9856 KB Output is correct
22 Correct 8 ms 9984 KB Output is correct
23 Correct 10 ms 10112 KB Output is correct
24 Correct 9 ms 10112 KB Output is correct
25 Correct 12 ms 9984 KB Output is correct
26 Correct 10 ms 10368 KB Output is correct
27 Correct 10 ms 10240 KB Output is correct
28 Correct 10 ms 10112 KB Output is correct
29 Correct 77 ms 19800 KB Output is correct
30 Correct 85 ms 19552 KB Output is correct
31 Correct 81 ms 19680 KB Output is correct
32 Correct 80 ms 19552 KB Output is correct
33 Correct 74 ms 15832 KB Output is correct
34 Correct 78 ms 15764 KB Output is correct
35 Correct 80 ms 19296 KB Output is correct
36 Correct 76 ms 19176 KB Output is correct
37 Correct 16 ms 10496 KB Output is correct
38 Correct 82 ms 19804 KB Output is correct
39 Correct 16 ms 10496 KB Output is correct
40 Correct 40 ms 11132 KB Output is correct
41 Correct 91 ms 19168 KB Output is correct
42 Correct 85 ms 19680 KB Output is correct
43 Correct 17 ms 10368 KB Output is correct
44 Correct 81 ms 19164 KB Output is correct
45 Correct 100 ms 19424 KB Output is correct
46 Correct 28 ms 10872 KB Output is correct
47 Correct 83 ms 19424 KB Output is correct
48 Correct 84 ms 20052 KB Output is correct
49 Correct 18 ms 10496 KB Output is correct
50 Correct 79 ms 14572 KB Output is correct
51 Correct 75 ms 18920 KB Output is correct
52 Correct 16 ms 10528 KB Output is correct
53 Correct 16 ms 10528 KB Output is correct
54 Correct 80 ms 15460 KB Output is correct
55 Correct 82 ms 15460 KB Output is correct
56 Correct 313 ms 45796 KB Output is correct
57 Correct 279 ms 40404 KB Output is correct
58 Correct 301 ms 42712 KB Output is correct
59 Correct 215 ms 34396 KB Output is correct
60 Correct 292 ms 42444 KB Output is correct
61 Correct 325 ms 43728 KB Output is correct
62 Correct 209 ms 30528 KB Output is correct
63 Correct 157 ms 25972 KB Output is correct
64 Correct 98 ms 18508 KB Output is correct
65 Correct 272 ms 40404 KB Output is correct
66 Correct 92 ms 16504 KB Output is correct
67 Correct 75 ms 13168 KB Output is correct
68 Correct 90 ms 19936 KB Output is correct
69 Correct 317 ms 42588 KB Output is correct
70 Correct 18 ms 10624 KB Output is correct
71 Correct 96 ms 20064 KB Output is correct
72 Correct 259 ms 34260 KB Output is correct
73 Correct 16 ms 10368 KB Output is correct
74 Correct 83 ms 16484 KB Output is correct
75 Correct 297 ms 46540 KB Output is correct
76 Correct 16 ms 10368 KB Output is correct
77 Correct 79 ms 15328 KB Output is correct
78 Correct 157 ms 26372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 11380 KB Output is correct
2 Correct 55 ms 10996 KB Output is correct
3 Correct 18 ms 10624 KB Output is correct
4 Correct 17 ms 10496 KB Output is correct
5 Correct 475 ms 54220 KB Output is correct
6 Correct 339 ms 49996 KB Output is correct
7 Correct 454 ms 53324 KB Output is correct
8 Correct 313 ms 50636 KB Output is correct
9 Correct 427 ms 54476 KB Output is correct
10 Correct 464 ms 54060 KB Output is correct
11 Correct 276 ms 43212 KB Output is correct
12 Correct 278 ms 42308 KB Output is correct
13 Correct 221 ms 35132 KB Output is correct
14 Correct 320 ms 45004 KB Output is correct
15 Correct 362 ms 49868 KB Output is correct
16 Correct 82 ms 15712 KB Output is correct
17 Correct 86 ms 19676 KB Output is correct
18 Correct 458 ms 53708 KB Output is correct
19 Correct 80 ms 20188 KB Output is correct
20 Correct 130 ms 24828 KB Output is correct
21 Correct 316 ms 50120 KB Output is correct
22 Correct 77 ms 15712 KB Output is correct
23 Correct 103 ms 19676 KB Output is correct
24 Correct 495 ms 55244 KB Output is correct
25 Correct 114 ms 18896 KB Output is correct
26 Correct 102 ms 16376 KB Output is correct
27 Correct 268 ms 42344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 10464 KB Output is correct
2 Correct 10 ms 10368 KB Output is correct
3 Correct 10 ms 10368 KB Output is correct
4 Correct 9 ms 10368 KB Output is correct
5 Correct 11 ms 10464 KB Output is correct
6 Correct 10 ms 10368 KB Output is correct
7 Correct 10 ms 10240 KB Output is correct
8 Correct 9 ms 10112 KB Output is correct
9 Correct 8 ms 9984 KB Output is correct
10 Correct 9 ms 10368 KB Output is correct
11 Correct 7 ms 9856 KB Output is correct
12 Correct 7 ms 9856 KB Output is correct
13 Correct 8 ms 9984 KB Output is correct
14 Correct 12 ms 10440 KB Output is correct
15 Correct 7 ms 9856 KB Output is correct
16 Correct 8 ms 9984 KB Output is correct
17 Correct 10 ms 10368 KB Output is correct
18 Correct 8 ms 9856 KB Output is correct
19 Correct 8 ms 10112 KB Output is correct
20 Correct 10 ms 10464 KB Output is correct
21 Correct 7 ms 9856 KB Output is correct
22 Correct 8 ms 9984 KB Output is correct
23 Correct 10 ms 10112 KB Output is correct
24 Correct 9 ms 10112 KB Output is correct
25 Correct 12 ms 9984 KB Output is correct
26 Correct 10 ms 10368 KB Output is correct
27 Correct 10 ms 10240 KB Output is correct
28 Correct 10 ms 10112 KB Output is correct
29 Correct 77 ms 19800 KB Output is correct
30 Correct 85 ms 19552 KB Output is correct
31 Correct 81 ms 19680 KB Output is correct
32 Correct 80 ms 19552 KB Output is correct
33 Correct 74 ms 15832 KB Output is correct
34 Correct 78 ms 15764 KB Output is correct
35 Correct 80 ms 19296 KB Output is correct
36 Correct 76 ms 19176 KB Output is correct
37 Correct 16 ms 10496 KB Output is correct
38 Correct 82 ms 19804 KB Output is correct
39 Correct 16 ms 10496 KB Output is correct
40 Correct 40 ms 11132 KB Output is correct
41 Correct 91 ms 19168 KB Output is correct
42 Correct 85 ms 19680 KB Output is correct
43 Correct 17 ms 10368 KB Output is correct
44 Correct 81 ms 19164 KB Output is correct
45 Correct 100 ms 19424 KB Output is correct
46 Correct 28 ms 10872 KB Output is correct
47 Correct 83 ms 19424 KB Output is correct
48 Correct 84 ms 20052 KB Output is correct
49 Correct 18 ms 10496 KB Output is correct
50 Correct 79 ms 14572 KB Output is correct
51 Correct 75 ms 18920 KB Output is correct
52 Correct 16 ms 10528 KB Output is correct
53 Correct 16 ms 10528 KB Output is correct
54 Correct 80 ms 15460 KB Output is correct
55 Correct 82 ms 15460 KB Output is correct
56 Correct 313 ms 45796 KB Output is correct
57 Correct 279 ms 40404 KB Output is correct
58 Correct 301 ms 42712 KB Output is correct
59 Correct 215 ms 34396 KB Output is correct
60 Correct 292 ms 42444 KB Output is correct
61 Correct 325 ms 43728 KB Output is correct
62 Correct 209 ms 30528 KB Output is correct
63 Correct 157 ms 25972 KB Output is correct
64 Correct 98 ms 18508 KB Output is correct
65 Correct 272 ms 40404 KB Output is correct
66 Correct 92 ms 16504 KB Output is correct
67 Correct 75 ms 13168 KB Output is correct
68 Correct 90 ms 19936 KB Output is correct
69 Correct 317 ms 42588 KB Output is correct
70 Correct 18 ms 10624 KB Output is correct
71 Correct 96 ms 20064 KB Output is correct
72 Correct 259 ms 34260 KB Output is correct
73 Correct 16 ms 10368 KB Output is correct
74 Correct 83 ms 16484 KB Output is correct
75 Correct 297 ms 46540 KB Output is correct
76 Correct 16 ms 10368 KB Output is correct
77 Correct 79 ms 15328 KB Output is correct
78 Correct 157 ms 26372 KB Output is correct
79 Correct 66 ms 11380 KB Output is correct
80 Correct 55 ms 10996 KB Output is correct
81 Correct 18 ms 10624 KB Output is correct
82 Correct 17 ms 10496 KB Output is correct
83 Correct 475 ms 54220 KB Output is correct
84 Correct 339 ms 49996 KB Output is correct
85 Correct 454 ms 53324 KB Output is correct
86 Correct 313 ms 50636 KB Output is correct
87 Correct 427 ms 54476 KB Output is correct
88 Correct 464 ms 54060 KB Output is correct
89 Correct 276 ms 43212 KB Output is correct
90 Correct 278 ms 42308 KB Output is correct
91 Correct 221 ms 35132 KB Output is correct
92 Correct 320 ms 45004 KB Output is correct
93 Correct 362 ms 49868 KB Output is correct
94 Correct 82 ms 15712 KB Output is correct
95 Correct 86 ms 19676 KB Output is correct
96 Correct 458 ms 53708 KB Output is correct
97 Correct 80 ms 20188 KB Output is correct
98 Correct 130 ms 24828 KB Output is correct
99 Correct 316 ms 50120 KB Output is correct
100 Correct 77 ms 15712 KB Output is correct
101 Correct 103 ms 19676 KB Output is correct
102 Correct 495 ms 55244 KB Output is correct
103 Correct 114 ms 18896 KB Output is correct
104 Correct 102 ms 16376 KB Output is correct
105 Correct 268 ms 42344 KB Output is correct
106 Correct 47 ms 10744 KB Output is correct
107 Correct 64 ms 11760 KB Output is correct
108 Correct 62 ms 11000 KB Output is correct
109 Correct 69 ms 11632 KB Output is correct
110 Correct 463 ms 56908 KB Output is correct
111 Correct 335 ms 46796 KB Output is correct
112 Correct 478 ms 55656 KB Output is correct
113 Correct 366 ms 51532 KB Output is correct
114 Correct 458 ms 56932 KB Output is correct
115 Correct 480 ms 55756 KB Output is correct
116 Correct 300 ms 49688 KB Output is correct
117 Correct 275 ms 43860 KB Output is correct
118 Correct 225 ms 36996 KB Output is correct
119 Correct 90 ms 16632 KB Output is correct
120 Correct 334 ms 46816 KB Output is correct
121 Correct 84 ms 20192 KB Output is correct
122 Correct 87 ms 20188 KB Output is correct
123 Correct 470 ms 54732 KB Output is correct
124 Correct 106 ms 16092 KB Output is correct
125 Correct 131 ms 25592 KB Output is correct
126 Correct 323 ms 50732 KB Output is correct
127 Correct 90 ms 15840 KB Output is correct
128 Correct 88 ms 20316 KB Output is correct
129 Correct 422 ms 54764 KB Output is correct
130 Correct 134 ms 21672 KB Output is correct
131 Correct 124 ms 20336 KB Output is correct
132 Correct 288 ms 45160 KB Output is correct