답안 #274976

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
274976 2020-08-20T03:11:15 Z ainta Shopping Plans (CCO20_day2problem3) C++17
25 / 25
339 ms 62260 KB
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#define N_ 201000
using namespace std;
int n, m, K;
struct QQ{
    long long s;
    int a;
    int isB;
    int c;
    int pv; // in a, c chosen, pv-th, ~ed
    int cur;
    int ed;
    bool operator <(const QQ &p)const{
        return s>p.s;
    }
};
priority_queue<QQ>PQ;
void Put(long long s, int a, int isB, int c, int pv, int cur, int ed){
    //printf("%lld %d %d %d %d %d %d\n",s,a,isB,c,pv,cur,ed);
    QQ t = {s,a,isB,c,pv,cur,ed};
    PQ.push(t);
}
struct AA{
    vector<int>G;
    int b, e, sz;
    int dif;
    bool operator <(const AA &p)const{
        return dif<p.dif;
    }
}U[N_],w[N_];
int cnt;
vector<long long>Res;
int main(){
    int i, j;
    scanf("%d%d%d",&n,&m,&K);
    for(i=1;i<=n;i++){
        int a, b;
        scanf("%d%d",&a,&b);
        U[a].G.push_back(b);
    }
    long long s=0;
    for(i=1;i<=m;i++){
        U[i].sz = U[i].G.size();
        scanf("%d%d",&U[i].b,&U[i].e);
        if(U[i].sz < U[i].b){
            for(i=0;i<K;i++)puts("-1");
            return 0;
        }
        U[i].e=min(U[i].e,U[i].sz);
        sort(U[i].G.begin(),U[i].G.end());
        for(j=0;j<U[i].b;j++)s+=U[i].G[j];
        if(U[i].b==U[i].sz || U[i].e==0)continue;
        cnt++;
        w[cnt].dif=U[i].G[U[i].b];
        if(U[i].b)w[cnt].dif -= U[i].G[U[i].b-1];
        w[cnt].b=U[i].b,w[cnt].e=U[i].e,w[cnt].sz=U[i].sz, w[cnt].G=U[i].G;
    }
    sort(w+1,w+cnt+1);
//    printf("%d %d\n",w[1].dif,w[2].dif);
//    printf("%d\n",cnt);
    Res.push_back(s);
    if(cnt){
        if(w[1].b)Put(s+w[1].dif, 1, 1, w[1].b, w[1].b, w[1].b+1, w[1].sz);
        else Put(s+w[1].dif, 1, 1, 1, 1, 1, w[1].sz);
    }
    while(!PQ.empty() && Res.size()<K){
        QQ tp = PQ.top();
        s = tp.s;
        Res.push_back(s);
        //printf("%lld\n",tp.s);
        PQ.pop();
        int a = tp.a;
        if(tp.isB && tp.c<w[a].e){
            //puts("11\n");
            if(w[a].b) Put(s + w[a].G[tp.c-1], a, 0, tp.c+1, tp.c+1, tp.c+1, w[a].sz);
        }
        if(tp.isB && a != cnt){
            //puts("22\n");
            if(w[a+1].b)Put(s - w[a].dif + w[a+1].dif, a+1, 1, w[a+1].b, w[a+1].b, w[a+1].b+1, w[a+1].sz);
            else Put(s - w[a].dif + w[a+1].dif, a+1, 1, 1, 1, 1, w[a+1].sz);
        }
        if(a!=cnt){
            //puts("33\n");
            if(w[a+1].b)Put(s + w[a+1].dif, a+1, 1, w[a+1].b, w[a+1].b, w[a+1].b+1, w[a+1].sz);
            else Put(s + w[a+1].dif, a+1, 1, 1, 1, 1, w[a+1].sz);
        }
        if(tp.c==tp.pv && tp.pv==tp.cur && tp.c<w[a].e){
            //puts("44\n");
            Put(s + w[a].G[tp.c], a, 0, tp.c+1, tp.c+1, tp.c+1, w[a].sz);
        }
        if(tp.cur < tp.ed){
            //puts("55\n");
            Put(s - w[a].G[tp.cur-1] + w[a].G[tp.cur], a, 0, tp.c, tp.pv, tp.cur+1, tp.ed);
        }
        if(tp.pv!=1 && tp.cur!=tp.pv){
            //puts("66\n");
            Put(s-w[a].G[tp.pv-2]+w[a].G[tp.pv-1], a, 0, tp.c, tp.pv-1, tp.pv, tp.cur-1);
        }
    }
    for(auto &t : Res)printf("%lld\n",t);
    for(i=Res.size();i<K;i++)puts("-1");
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:69:36: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   69 |     while(!PQ.empty() && Res.size()<K){
      |                          ~~~~~~~~~~^~
Main.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   38 |     scanf("%d%d%d",&n,&m,&K);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   41 |         scanf("%d%d",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~
Main.cpp:47:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   47 |         scanf("%d%d",&U[i].b,&U[i].e);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 16704 KB Output is correct
2 Correct 13 ms 16704 KB Output is correct
3 Correct 15 ms 16704 KB Output is correct
4 Correct 13 ms 16704 KB Output is correct
5 Correct 13 ms 16704 KB Output is correct
6 Correct 13 ms 16640 KB Output is correct
7 Correct 14 ms 16512 KB Output is correct
8 Correct 12 ms 16512 KB Output is correct
9 Correct 12 ms 16244 KB Output is correct
10 Correct 13 ms 16704 KB Output is correct
11 Correct 11 ms 16128 KB Output is correct
12 Correct 11 ms 16256 KB Output is correct
13 Correct 14 ms 16384 KB Output is correct
14 Correct 14 ms 16704 KB Output is correct
15 Correct 11 ms 16256 KB Output is correct
16 Correct 11 ms 16384 KB Output is correct
17 Correct 14 ms 16704 KB Output is correct
18 Correct 11 ms 16256 KB Output is correct
19 Correct 11 ms 16384 KB Output is correct
20 Correct 14 ms 16704 KB Output is correct
21 Correct 10 ms 16128 KB Output is correct
22 Correct 11 ms 16384 KB Output is correct
23 Correct 12 ms 16512 KB Output is correct
24 Correct 12 ms 16256 KB Output is correct
25 Correct 12 ms 16256 KB Output is correct
26 Correct 13 ms 16576 KB Output is correct
27 Correct 13 ms 16576 KB Output is correct
28 Correct 13 ms 16512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 88 ms 36024 KB Output is correct
2 Correct 93 ms 35740 KB Output is correct
3 Correct 94 ms 35860 KB Output is correct
4 Correct 90 ms 35872 KB Output is correct
5 Correct 82 ms 29288 KB Output is correct
6 Correct 80 ms 28952 KB Output is correct
7 Correct 95 ms 35664 KB Output is correct
8 Correct 89 ms 36360 KB Output is correct
9 Correct 20 ms 16768 KB Output is correct
10 Correct 96 ms 35888 KB Output is correct
11 Correct 16 ms 16768 KB Output is correct
12 Correct 39 ms 18536 KB Output is correct
13 Correct 98 ms 35936 KB Output is correct
14 Correct 97 ms 35860 KB Output is correct
15 Correct 16 ms 16848 KB Output is correct
16 Correct 108 ms 35932 KB Output is correct
17 Correct 93 ms 35732 KB Output is correct
18 Correct 28 ms 17784 KB Output is correct
19 Correct 91 ms 36048 KB Output is correct
20 Correct 89 ms 36124 KB Output is correct
21 Correct 19 ms 16896 KB Output is correct
22 Correct 89 ms 27860 KB Output is correct
23 Correct 89 ms 35920 KB Output is correct
24 Correct 19 ms 16768 KB Output is correct
25 Correct 16 ms 16768 KB Output is correct
26 Correct 81 ms 27728 KB Output is correct
27 Correct 77 ms 27728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 16704 KB Output is correct
2 Correct 13 ms 16704 KB Output is correct
3 Correct 15 ms 16704 KB Output is correct
4 Correct 13 ms 16704 KB Output is correct
5 Correct 13 ms 16704 KB Output is correct
6 Correct 13 ms 16640 KB Output is correct
7 Correct 14 ms 16512 KB Output is correct
8 Correct 12 ms 16512 KB Output is correct
9 Correct 12 ms 16244 KB Output is correct
10 Correct 13 ms 16704 KB Output is correct
11 Correct 11 ms 16128 KB Output is correct
12 Correct 11 ms 16256 KB Output is correct
13 Correct 14 ms 16384 KB Output is correct
14 Correct 14 ms 16704 KB Output is correct
15 Correct 11 ms 16256 KB Output is correct
16 Correct 11 ms 16384 KB Output is correct
17 Correct 14 ms 16704 KB Output is correct
18 Correct 11 ms 16256 KB Output is correct
19 Correct 11 ms 16384 KB Output is correct
20 Correct 14 ms 16704 KB Output is correct
21 Correct 10 ms 16128 KB Output is correct
22 Correct 11 ms 16384 KB Output is correct
23 Correct 12 ms 16512 KB Output is correct
24 Correct 12 ms 16256 KB Output is correct
25 Correct 12 ms 16256 KB Output is correct
26 Correct 13 ms 16576 KB Output is correct
27 Correct 13 ms 16576 KB Output is correct
28 Correct 13 ms 16512 KB Output is correct
29 Correct 88 ms 36024 KB Output is correct
30 Correct 93 ms 35740 KB Output is correct
31 Correct 94 ms 35860 KB Output is correct
32 Correct 90 ms 35872 KB Output is correct
33 Correct 82 ms 29288 KB Output is correct
34 Correct 80 ms 28952 KB Output is correct
35 Correct 95 ms 35664 KB Output is correct
36 Correct 89 ms 36360 KB Output is correct
37 Correct 20 ms 16768 KB Output is correct
38 Correct 96 ms 35888 KB Output is correct
39 Correct 16 ms 16768 KB Output is correct
40 Correct 39 ms 18536 KB Output is correct
41 Correct 98 ms 35936 KB Output is correct
42 Correct 97 ms 35860 KB Output is correct
43 Correct 16 ms 16848 KB Output is correct
44 Correct 108 ms 35932 KB Output is correct
45 Correct 93 ms 35732 KB Output is correct
46 Correct 28 ms 17784 KB Output is correct
47 Correct 91 ms 36048 KB Output is correct
48 Correct 89 ms 36124 KB Output is correct
49 Correct 19 ms 16896 KB Output is correct
50 Correct 89 ms 27860 KB Output is correct
51 Correct 89 ms 35920 KB Output is correct
52 Correct 19 ms 16768 KB Output is correct
53 Correct 16 ms 16768 KB Output is correct
54 Correct 81 ms 27728 KB Output is correct
55 Correct 77 ms 27728 KB Output is correct
56 Correct 259 ms 45212 KB Output is correct
57 Correct 232 ms 43216 KB Output is correct
58 Correct 252 ms 44052 KB Output is correct
59 Correct 212 ms 41816 KB Output is correct
60 Correct 270 ms 40400 KB Output is correct
61 Correct 249 ms 45008 KB Output is correct
62 Correct 211 ms 40992 KB Output is correct
63 Correct 176 ms 39640 KB Output is correct
64 Correct 112 ms 23668 KB Output is correct
65 Correct 248 ms 43216 KB Output is correct
66 Correct 119 ms 22776 KB Output is correct
67 Correct 77 ms 21840 KB Output is correct
68 Correct 124 ms 35792 KB Output is correct
69 Correct 270 ms 43924 KB Output is correct
70 Correct 19 ms 17152 KB Output is correct
71 Correct 126 ms 35800 KB Output is correct
72 Correct 222 ms 41816 KB Output is correct
73 Correct 16 ms 16768 KB Output is correct
74 Correct 107 ms 30252 KB Output is correct
75 Correct 272 ms 45540 KB Output is correct
76 Correct 17 ms 16768 KB Output is correct
77 Correct 114 ms 28416 KB Output is correct
78 Correct 183 ms 39912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 20444 KB Output is correct
2 Correct 55 ms 18908 KB Output is correct
3 Correct 18 ms 16896 KB Output is correct
4 Correct 17 ms 16896 KB Output is correct
5 Correct 288 ms 45876 KB Output is correct
6 Correct 277 ms 43700 KB Output is correct
7 Correct 278 ms 43728 KB Output is correct
8 Correct 271 ms 45028 KB Output is correct
9 Correct 294 ms 45824 KB Output is correct
10 Correct 293 ms 44512 KB Output is correct
11 Correct 279 ms 58688 KB Output is correct
12 Correct 213 ms 34512 KB Output is correct
13 Correct 182 ms 25612 KB Output is correct
14 Correct 271 ms 44128 KB Output is correct
15 Correct 280 ms 45396 KB Output is correct
16 Correct 125 ms 35920 KB Output is correct
17 Correct 130 ms 35132 KB Output is correct
18 Correct 326 ms 62260 KB Output is correct
19 Correct 125 ms 35792 KB Output is correct
20 Correct 132 ms 36452 KB Output is correct
21 Correct 266 ms 45116 KB Output is correct
22 Correct 121 ms 36036 KB Output is correct
23 Correct 139 ms 34620 KB Output is correct
24 Correct 299 ms 47192 KB Output is correct
25 Correct 102 ms 29380 KB Output is correct
26 Correct 94 ms 29008 KB Output is correct
27 Correct 220 ms 41324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 16704 KB Output is correct
2 Correct 13 ms 16704 KB Output is correct
3 Correct 15 ms 16704 KB Output is correct
4 Correct 13 ms 16704 KB Output is correct
5 Correct 13 ms 16704 KB Output is correct
6 Correct 13 ms 16640 KB Output is correct
7 Correct 14 ms 16512 KB Output is correct
8 Correct 12 ms 16512 KB Output is correct
9 Correct 12 ms 16244 KB Output is correct
10 Correct 13 ms 16704 KB Output is correct
11 Correct 11 ms 16128 KB Output is correct
12 Correct 11 ms 16256 KB Output is correct
13 Correct 14 ms 16384 KB Output is correct
14 Correct 14 ms 16704 KB Output is correct
15 Correct 11 ms 16256 KB Output is correct
16 Correct 11 ms 16384 KB Output is correct
17 Correct 14 ms 16704 KB Output is correct
18 Correct 11 ms 16256 KB Output is correct
19 Correct 11 ms 16384 KB Output is correct
20 Correct 14 ms 16704 KB Output is correct
21 Correct 10 ms 16128 KB Output is correct
22 Correct 11 ms 16384 KB Output is correct
23 Correct 12 ms 16512 KB Output is correct
24 Correct 12 ms 16256 KB Output is correct
25 Correct 12 ms 16256 KB Output is correct
26 Correct 13 ms 16576 KB Output is correct
27 Correct 13 ms 16576 KB Output is correct
28 Correct 13 ms 16512 KB Output is correct
29 Correct 88 ms 36024 KB Output is correct
30 Correct 93 ms 35740 KB Output is correct
31 Correct 94 ms 35860 KB Output is correct
32 Correct 90 ms 35872 KB Output is correct
33 Correct 82 ms 29288 KB Output is correct
34 Correct 80 ms 28952 KB Output is correct
35 Correct 95 ms 35664 KB Output is correct
36 Correct 89 ms 36360 KB Output is correct
37 Correct 20 ms 16768 KB Output is correct
38 Correct 96 ms 35888 KB Output is correct
39 Correct 16 ms 16768 KB Output is correct
40 Correct 39 ms 18536 KB Output is correct
41 Correct 98 ms 35936 KB Output is correct
42 Correct 97 ms 35860 KB Output is correct
43 Correct 16 ms 16848 KB Output is correct
44 Correct 108 ms 35932 KB Output is correct
45 Correct 93 ms 35732 KB Output is correct
46 Correct 28 ms 17784 KB Output is correct
47 Correct 91 ms 36048 KB Output is correct
48 Correct 89 ms 36124 KB Output is correct
49 Correct 19 ms 16896 KB Output is correct
50 Correct 89 ms 27860 KB Output is correct
51 Correct 89 ms 35920 KB Output is correct
52 Correct 19 ms 16768 KB Output is correct
53 Correct 16 ms 16768 KB Output is correct
54 Correct 81 ms 27728 KB Output is correct
55 Correct 77 ms 27728 KB Output is correct
56 Correct 259 ms 45212 KB Output is correct
57 Correct 232 ms 43216 KB Output is correct
58 Correct 252 ms 44052 KB Output is correct
59 Correct 212 ms 41816 KB Output is correct
60 Correct 270 ms 40400 KB Output is correct
61 Correct 249 ms 45008 KB Output is correct
62 Correct 211 ms 40992 KB Output is correct
63 Correct 176 ms 39640 KB Output is correct
64 Correct 112 ms 23668 KB Output is correct
65 Correct 248 ms 43216 KB Output is correct
66 Correct 119 ms 22776 KB Output is correct
67 Correct 77 ms 21840 KB Output is correct
68 Correct 124 ms 35792 KB Output is correct
69 Correct 270 ms 43924 KB Output is correct
70 Correct 19 ms 17152 KB Output is correct
71 Correct 126 ms 35800 KB Output is correct
72 Correct 222 ms 41816 KB Output is correct
73 Correct 16 ms 16768 KB Output is correct
74 Correct 107 ms 30252 KB Output is correct
75 Correct 272 ms 45540 KB Output is correct
76 Correct 17 ms 16768 KB Output is correct
77 Correct 114 ms 28416 KB Output is correct
78 Correct 183 ms 39912 KB Output is correct
79 Correct 66 ms 20444 KB Output is correct
80 Correct 55 ms 18908 KB Output is correct
81 Correct 18 ms 16896 KB Output is correct
82 Correct 17 ms 16896 KB Output is correct
83 Correct 288 ms 45876 KB Output is correct
84 Correct 277 ms 43700 KB Output is correct
85 Correct 278 ms 43728 KB Output is correct
86 Correct 271 ms 45028 KB Output is correct
87 Correct 294 ms 45824 KB Output is correct
88 Correct 293 ms 44512 KB Output is correct
89 Correct 279 ms 58688 KB Output is correct
90 Correct 213 ms 34512 KB Output is correct
91 Correct 182 ms 25612 KB Output is correct
92 Correct 271 ms 44128 KB Output is correct
93 Correct 280 ms 45396 KB Output is correct
94 Correct 125 ms 35920 KB Output is correct
95 Correct 130 ms 35132 KB Output is correct
96 Correct 326 ms 62260 KB Output is correct
97 Correct 125 ms 35792 KB Output is correct
98 Correct 132 ms 36452 KB Output is correct
99 Correct 266 ms 45116 KB Output is correct
100 Correct 121 ms 36036 KB Output is correct
101 Correct 139 ms 34620 KB Output is correct
102 Correct 299 ms 47192 KB Output is correct
103 Correct 102 ms 29380 KB Output is correct
104 Correct 94 ms 29008 KB Output is correct
105 Correct 220 ms 41324 KB Output is correct
106 Correct 59 ms 18952 KB Output is correct
107 Correct 67 ms 21852 KB Output is correct
108 Correct 62 ms 19932 KB Output is correct
109 Correct 68 ms 20712 KB Output is correct
110 Correct 316 ms 46832 KB Output is correct
111 Correct 330 ms 60920 KB Output is correct
112 Correct 307 ms 61860 KB Output is correct
113 Correct 302 ms 60084 KB Output is correct
114 Correct 295 ms 46792 KB Output is correct
115 Correct 339 ms 45496 KB Output is correct
116 Correct 289 ms 58592 KB Output is correct
117 Correct 258 ms 42732 KB Output is correct
118 Correct 196 ms 27856 KB Output is correct
119 Correct 132 ms 23032 KB Output is correct
120 Correct 313 ms 60896 KB Output is correct
121 Correct 138 ms 34520 KB Output is correct
122 Correct 141 ms 34876 KB Output is correct
123 Correct 326 ms 61500 KB Output is correct
124 Correct 133 ms 35920 KB Output is correct
125 Correct 149 ms 37592 KB Output is correct
126 Correct 266 ms 44416 KB Output is correct
127 Correct 97 ms 29904 KB Output is correct
128 Correct 112 ms 35920 KB Output is correct
129 Correct 279 ms 45940 KB Output is correct
130 Correct 117 ms 34520 KB Output is correct
131 Correct 125 ms 35772 KB Output is correct
132 Correct 246 ms 41560 KB Output is correct