#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18;
struct type
{
int x,y;
int sz;
vector<int>lst;
int fdif;
type(){}
};
struct node
{
ll val;
int ci,cn;
int ith,pos,mx;
bool fi;
node(ll val,int ci,int cn,int ith,int pos,int mx,bool fi=0):
val(val),ci(ci),cn(cn),ith(ith),pos(pos),mx(mx),fi(fi){}
bool operator<(const node&x)const
{
return val==x.val?fi&&!x.fi:val>x.val;
}
};
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n,m,k;
cin>>n>>m>>k;
vector<vector<int> >vv(m);
for(int i=0;i<n;i++)
{
int a,c;
cin>>a>>c;
vv[a-1].eb(c);
}
vector<type>tpv;
ll fi=0;
for(auto&v:vv)
{
int x,y;
cin>>x>>y;
sort(all(v));
y=min(y,(int)v.size());
if(x>y)
{
for(int i=0;i<k;i++)
cout<<"-1\n";
return 0;
}
for(int i=0;i<x;i++)
fi+=v[i];
if((int)v.size()>x)
{
tpv.eb(type());
if(x==0)
tpv.back().fdif=v[0];
else
tpv.back().fdif=v[x]-v[x-1];
tpv.back().x=x,tpv.back().y=y;
tpv.back().lst=v;
tpv.back().sz=v.size();
}
}
sort(all(tpv),[](const type&x,const type&y){return x.fdif<y.fdif;});
vector<ll>ansv;
ansv.eb(fi);
priority_queue<node>pq;
if(!tpv.empty())
{
if(tpv[0].x==0)
pq.ep(fi+tpv[0].fdif,0,tpv[0].x,0,0,0,1);
else
pq.ep(fi+tpv[0].fdif,0,tpv[0].x,tpv[0].x-1,tpv[0].x-1,tpv[0].sz-1,1);
}
int tps=tpv.size();
while(!pq.empty()&&(int)ansv.size()<k)
{
node cur=pq.top();
pq.pop();
const type&tp=tpv[cur.ci];
if(cur.first)
cur.val-=tp.fdif;
else
ansv.eb(cur.val);
if(cur.ith>0&&cur.pos>cur.ith)
pq.ep(cur.val-tp.lst[cur.ith-1]+tp.lst[cur.ith],cur.ci,cur.cn,cur.ith-1,cur.ith,cur.pos-1);
if(cur.pos<cur.mx)
pq.ep(cur.val-tp.lst[cur.pos]+tp.lst[cur.pos+1],cur.ci,cur.cn,cur.ith,cur.pos+1,cur.mx);
if(cur.pos==cur.cn-1&&cur.cn<tp.y)
pq.ep(cur.val+tp.lst[cur.cn],cur.ci,cur.cn+1,cur.cn,cur.cn,cur.mx);
if(cur.ci+1<tps)
{
const type&ntp=tpv[cur.ci+1];
if(ntp.x==0)
pq.ep(cur.val+ntp.fdif,cur.ci+1,ntp.x,0,0,0,1);
else
pq.ep(cur.val+ntp.fdif,cur.ci+1,ntp.x,ntp.x-1,ntp.x-1,ntp.sz-1,1);
}
}
while((int)ansv.size()<k)
ansv.eb(-1);
for(ll&t:ansv)
cout<<t<<'\n';
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:16:8: warning: '<anonymous>.type::x' may be used uninitialized in this function [-Wmaybe-uninitialized]
16 | struct type
| ^~~~
Main.cpp:16:8: warning: '<anonymous>.type::y' may be used uninitialized in this function [-Wmaybe-uninitialized]
Main.cpp:16:8: warning: '<anonymous>.type::sz' may be used uninitialized in this function [-Wmaybe-uninitialized]
Main.cpp:16:8: warning: '<anonymous>.type::fdif' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1152 KB |
Output is correct |
2 |
Correct |
4 ms |
1024 KB |
Output is correct |
3 |
Correct |
4 ms |
1024 KB |
Output is correct |
4 |
Correct |
4 ms |
896 KB |
Output is correct |
5 |
Correct |
4 ms |
1024 KB |
Output is correct |
6 |
Correct |
5 ms |
1024 KB |
Output is correct |
7 |
Correct |
3 ms |
896 KB |
Output is correct |
8 |
Correct |
3 ms |
768 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
4 ms |
1024 KB |
Output is correct |
11 |
Correct |
2 ms |
512 KB |
Output is correct |
12 |
Correct |
2 ms |
640 KB |
Output is correct |
13 |
Correct |
3 ms |
828 KB |
Output is correct |
14 |
Correct |
4 ms |
1024 KB |
Output is correct |
15 |
Correct |
2 ms |
640 KB |
Output is correct |
16 |
Correct |
2 ms |
832 KB |
Output is correct |
17 |
Correct |
4 ms |
896 KB |
Output is correct |
18 |
Correct |
2 ms |
512 KB |
Output is correct |
19 |
Correct |
3 ms |
864 KB |
Output is correct |
20 |
Correct |
4 ms |
1056 KB |
Output is correct |
21 |
Correct |
1 ms |
512 KB |
Output is correct |
22 |
Correct |
2 ms |
768 KB |
Output is correct |
23 |
Correct |
4 ms |
768 KB |
Output is correct |
24 |
Correct |
3 ms |
640 KB |
Output is correct |
25 |
Correct |
2 ms |
640 KB |
Output is correct |
26 |
Correct |
4 ms |
1024 KB |
Output is correct |
27 |
Correct |
4 ms |
896 KB |
Output is correct |
28 |
Correct |
3 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
127 ms |
20372 KB |
Output is correct |
2 |
Correct |
136 ms |
20176 KB |
Output is correct |
3 |
Correct |
127 ms |
20304 KB |
Output is correct |
4 |
Correct |
121 ms |
20176 KB |
Output is correct |
5 |
Correct |
116 ms |
13684 KB |
Output is correct |
6 |
Correct |
112 ms |
13432 KB |
Output is correct |
7 |
Correct |
126 ms |
20104 KB |
Output is correct |
8 |
Correct |
101 ms |
20304 KB |
Output is correct |
9 |
Correct |
19 ms |
2744 KB |
Output is correct |
10 |
Correct |
128 ms |
20176 KB |
Output is correct |
11 |
Correct |
8 ms |
1024 KB |
Output is correct |
12 |
Correct |
45 ms |
3576 KB |
Output is correct |
13 |
Correct |
124 ms |
20244 KB |
Output is correct |
14 |
Correct |
124 ms |
20304 KB |
Output is correct |
15 |
Correct |
19 ms |
2804 KB |
Output is correct |
16 |
Correct |
124 ms |
20116 KB |
Output is correct |
17 |
Correct |
121 ms |
20048 KB |
Output is correct |
18 |
Correct |
36 ms |
3176 KB |
Output is correct |
19 |
Correct |
138 ms |
20376 KB |
Output is correct |
20 |
Correct |
124 ms |
20596 KB |
Output is correct |
21 |
Correct |
20 ms |
2672 KB |
Output is correct |
22 |
Correct |
114 ms |
12180 KB |
Output is correct |
23 |
Correct |
114 ms |
20136 KB |
Output is correct |
24 |
Correct |
9 ms |
1152 KB |
Output is correct |
25 |
Correct |
8 ms |
1220 KB |
Output is correct |
26 |
Correct |
114 ms |
12112 KB |
Output is correct |
27 |
Correct |
112 ms |
12112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1152 KB |
Output is correct |
2 |
Correct |
4 ms |
1024 KB |
Output is correct |
3 |
Correct |
4 ms |
1024 KB |
Output is correct |
4 |
Correct |
4 ms |
896 KB |
Output is correct |
5 |
Correct |
4 ms |
1024 KB |
Output is correct |
6 |
Correct |
5 ms |
1024 KB |
Output is correct |
7 |
Correct |
3 ms |
896 KB |
Output is correct |
8 |
Correct |
3 ms |
768 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
4 ms |
1024 KB |
Output is correct |
11 |
Correct |
2 ms |
512 KB |
Output is correct |
12 |
Correct |
2 ms |
640 KB |
Output is correct |
13 |
Correct |
3 ms |
828 KB |
Output is correct |
14 |
Correct |
4 ms |
1024 KB |
Output is correct |
15 |
Correct |
2 ms |
640 KB |
Output is correct |
16 |
Correct |
2 ms |
832 KB |
Output is correct |
17 |
Correct |
4 ms |
896 KB |
Output is correct |
18 |
Correct |
2 ms |
512 KB |
Output is correct |
19 |
Correct |
3 ms |
864 KB |
Output is correct |
20 |
Correct |
4 ms |
1056 KB |
Output is correct |
21 |
Correct |
1 ms |
512 KB |
Output is correct |
22 |
Correct |
2 ms |
768 KB |
Output is correct |
23 |
Correct |
4 ms |
768 KB |
Output is correct |
24 |
Correct |
3 ms |
640 KB |
Output is correct |
25 |
Correct |
2 ms |
640 KB |
Output is correct |
26 |
Correct |
4 ms |
1024 KB |
Output is correct |
27 |
Correct |
4 ms |
896 KB |
Output is correct |
28 |
Correct |
3 ms |
768 KB |
Output is correct |
29 |
Correct |
127 ms |
20372 KB |
Output is correct |
30 |
Correct |
136 ms |
20176 KB |
Output is correct |
31 |
Correct |
127 ms |
20304 KB |
Output is correct |
32 |
Correct |
121 ms |
20176 KB |
Output is correct |
33 |
Correct |
116 ms |
13684 KB |
Output is correct |
34 |
Correct |
112 ms |
13432 KB |
Output is correct |
35 |
Correct |
126 ms |
20104 KB |
Output is correct |
36 |
Correct |
101 ms |
20304 KB |
Output is correct |
37 |
Correct |
19 ms |
2744 KB |
Output is correct |
38 |
Correct |
128 ms |
20176 KB |
Output is correct |
39 |
Correct |
8 ms |
1024 KB |
Output is correct |
40 |
Correct |
45 ms |
3576 KB |
Output is correct |
41 |
Correct |
124 ms |
20244 KB |
Output is correct |
42 |
Correct |
124 ms |
20304 KB |
Output is correct |
43 |
Correct |
19 ms |
2804 KB |
Output is correct |
44 |
Correct |
124 ms |
20116 KB |
Output is correct |
45 |
Correct |
121 ms |
20048 KB |
Output is correct |
46 |
Correct |
36 ms |
3176 KB |
Output is correct |
47 |
Correct |
138 ms |
20376 KB |
Output is correct |
48 |
Correct |
124 ms |
20596 KB |
Output is correct |
49 |
Correct |
20 ms |
2672 KB |
Output is correct |
50 |
Correct |
114 ms |
12180 KB |
Output is correct |
51 |
Correct |
114 ms |
20136 KB |
Output is correct |
52 |
Correct |
9 ms |
1152 KB |
Output is correct |
53 |
Correct |
8 ms |
1220 KB |
Output is correct |
54 |
Correct |
114 ms |
12112 KB |
Output is correct |
55 |
Correct |
112 ms |
12112 KB |
Output is correct |
56 |
Correct |
286 ms |
35156 KB |
Output is correct |
57 |
Correct |
269 ms |
31252 KB |
Output is correct |
58 |
Correct |
271 ms |
33056 KB |
Output is correct |
59 |
Correct |
238 ms |
27540 KB |
Output is correct |
60 |
Correct |
272 ms |
30304 KB |
Output is correct |
61 |
Correct |
267 ms |
36112 KB |
Output is correct |
62 |
Correct |
233 ms |
26432 KB |
Output is correct |
63 |
Correct |
194 ms |
23896 KB |
Output is correct |
64 |
Correct |
90 ms |
7912 KB |
Output is correct |
65 |
Correct |
254 ms |
31164 KB |
Output is correct |
66 |
Correct |
87 ms |
8952 KB |
Output is correct |
67 |
Correct |
93 ms |
7780 KB |
Output is correct |
68 |
Correct |
148 ms |
20152 KB |
Output is correct |
69 |
Correct |
276 ms |
33004 KB |
Output is correct |
70 |
Correct |
22 ms |
2928 KB |
Output is correct |
71 |
Correct |
149 ms |
20092 KB |
Output is correct |
72 |
Correct |
258 ms |
27416 KB |
Output is correct |
73 |
Correct |
19 ms |
2672 KB |
Output is correct |
74 |
Correct |
131 ms |
14612 KB |
Output is correct |
75 |
Correct |
280 ms |
35356 KB |
Output is correct |
76 |
Correct |
19 ms |
2676 KB |
Output is correct |
77 |
Correct |
120 ms |
12820 KB |
Output is correct |
78 |
Correct |
182 ms |
24168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
21 ms |
2672 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1152 KB |
Output is correct |
2 |
Correct |
4 ms |
1024 KB |
Output is correct |
3 |
Correct |
4 ms |
1024 KB |
Output is correct |
4 |
Correct |
4 ms |
896 KB |
Output is correct |
5 |
Correct |
4 ms |
1024 KB |
Output is correct |
6 |
Correct |
5 ms |
1024 KB |
Output is correct |
7 |
Correct |
3 ms |
896 KB |
Output is correct |
8 |
Correct |
3 ms |
768 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
4 ms |
1024 KB |
Output is correct |
11 |
Correct |
2 ms |
512 KB |
Output is correct |
12 |
Correct |
2 ms |
640 KB |
Output is correct |
13 |
Correct |
3 ms |
828 KB |
Output is correct |
14 |
Correct |
4 ms |
1024 KB |
Output is correct |
15 |
Correct |
2 ms |
640 KB |
Output is correct |
16 |
Correct |
2 ms |
832 KB |
Output is correct |
17 |
Correct |
4 ms |
896 KB |
Output is correct |
18 |
Correct |
2 ms |
512 KB |
Output is correct |
19 |
Correct |
3 ms |
864 KB |
Output is correct |
20 |
Correct |
4 ms |
1056 KB |
Output is correct |
21 |
Correct |
1 ms |
512 KB |
Output is correct |
22 |
Correct |
2 ms |
768 KB |
Output is correct |
23 |
Correct |
4 ms |
768 KB |
Output is correct |
24 |
Correct |
3 ms |
640 KB |
Output is correct |
25 |
Correct |
2 ms |
640 KB |
Output is correct |
26 |
Correct |
4 ms |
1024 KB |
Output is correct |
27 |
Correct |
4 ms |
896 KB |
Output is correct |
28 |
Correct |
3 ms |
768 KB |
Output is correct |
29 |
Correct |
127 ms |
20372 KB |
Output is correct |
30 |
Correct |
136 ms |
20176 KB |
Output is correct |
31 |
Correct |
127 ms |
20304 KB |
Output is correct |
32 |
Correct |
121 ms |
20176 KB |
Output is correct |
33 |
Correct |
116 ms |
13684 KB |
Output is correct |
34 |
Correct |
112 ms |
13432 KB |
Output is correct |
35 |
Correct |
126 ms |
20104 KB |
Output is correct |
36 |
Correct |
101 ms |
20304 KB |
Output is correct |
37 |
Correct |
19 ms |
2744 KB |
Output is correct |
38 |
Correct |
128 ms |
20176 KB |
Output is correct |
39 |
Correct |
8 ms |
1024 KB |
Output is correct |
40 |
Correct |
45 ms |
3576 KB |
Output is correct |
41 |
Correct |
124 ms |
20244 KB |
Output is correct |
42 |
Correct |
124 ms |
20304 KB |
Output is correct |
43 |
Correct |
19 ms |
2804 KB |
Output is correct |
44 |
Correct |
124 ms |
20116 KB |
Output is correct |
45 |
Correct |
121 ms |
20048 KB |
Output is correct |
46 |
Correct |
36 ms |
3176 KB |
Output is correct |
47 |
Correct |
138 ms |
20376 KB |
Output is correct |
48 |
Correct |
124 ms |
20596 KB |
Output is correct |
49 |
Correct |
20 ms |
2672 KB |
Output is correct |
50 |
Correct |
114 ms |
12180 KB |
Output is correct |
51 |
Correct |
114 ms |
20136 KB |
Output is correct |
52 |
Correct |
9 ms |
1152 KB |
Output is correct |
53 |
Correct |
8 ms |
1220 KB |
Output is correct |
54 |
Correct |
114 ms |
12112 KB |
Output is correct |
55 |
Correct |
112 ms |
12112 KB |
Output is correct |
56 |
Correct |
286 ms |
35156 KB |
Output is correct |
57 |
Correct |
269 ms |
31252 KB |
Output is correct |
58 |
Correct |
271 ms |
33056 KB |
Output is correct |
59 |
Correct |
238 ms |
27540 KB |
Output is correct |
60 |
Correct |
272 ms |
30304 KB |
Output is correct |
61 |
Correct |
267 ms |
36112 KB |
Output is correct |
62 |
Correct |
233 ms |
26432 KB |
Output is correct |
63 |
Correct |
194 ms |
23896 KB |
Output is correct |
64 |
Correct |
90 ms |
7912 KB |
Output is correct |
65 |
Correct |
254 ms |
31164 KB |
Output is correct |
66 |
Correct |
87 ms |
8952 KB |
Output is correct |
67 |
Correct |
93 ms |
7780 KB |
Output is correct |
68 |
Correct |
148 ms |
20152 KB |
Output is correct |
69 |
Correct |
276 ms |
33004 KB |
Output is correct |
70 |
Correct |
22 ms |
2928 KB |
Output is correct |
71 |
Correct |
149 ms |
20092 KB |
Output is correct |
72 |
Correct |
258 ms |
27416 KB |
Output is correct |
73 |
Correct |
19 ms |
2672 KB |
Output is correct |
74 |
Correct |
131 ms |
14612 KB |
Output is correct |
75 |
Correct |
280 ms |
35356 KB |
Output is correct |
76 |
Correct |
19 ms |
2676 KB |
Output is correct |
77 |
Correct |
120 ms |
12820 KB |
Output is correct |
78 |
Correct |
182 ms |
24168 KB |
Output is correct |
79 |
Incorrect |
21 ms |
2672 KB |
Output isn't correct |
80 |
Halted |
0 ms |
0 KB |
- |