#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
//ifstream cin("a.in");
//ofstream cout("a.out");
long long inf=1e9+10;
struct node
{
long long layer,sum,lst,biti;
};
struct cmp
{
bool operator()(node a,node b)
{
return a.sum>b.sum;
}
};
priority_queue<node,vector<node>,cmp>pq;
vector<long long >arr;
vector<long long >adj[200005];
long long cost[200005];
vector<long long>ord;
bool cmp2(long long a,long long b)
{
return cost[a]<cost[b];
}
int y[200005];
signed main()
{
long long n,m,k,i,a,b,x;
long long sum=0;
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>m>>k;
for(i=1; i<=n; i++)
{
cin>>a>>b;
adj[a].push_back(b);
}
long long imp=0,minim=inf,poz=m;
for(i=1; i<=m; i++)
{
cin>>x>>y[i];
if(y[i]==0)
{
cost[i]=inf;
}
else
{
if(x==0)
{
adj[i].push_back(0);
}
sort(adj[i].begin(),adj[i].end());
if(adj[i].size()<x)
{
for(long long j=1; j<=k; j++)
{
cout<<-1<<'\n';
}
return 0;
}
long long vkuk=adj[i][0];
sum+=adj[i][0];
for(long long j=0; j<adj[i].size(); j++)
{
adj[i][j]-=vkuk;
}
if(adj[i].size()>=2)
{
cost[i]=adj[i][1];
}
else
{
cost[i]=inf;
}
}
ord.push_back(i);
}
sort(ord.begin(),ord.end(),cmp2);
m--;
for(i=0; i<ord.size(); i++)
{
if(cost[ord[i]]==inf)
{
m=i-1;
break;
}
}
node curr,curr2;
cout<<sum<<'\n';
k--;
if(m>=0)
{
pq.push({0,adj[ord[0]][1],1,1});
while(pq.size() && k && imp==0)
{
curr=pq.top();
pq.pop();
k--;
cout<<curr.sum+sum<<'\n';
if(curr.lst==1 && curr.layer+1<=m)
{
curr2=curr;
curr2.layer++;
curr2.biti=1;
curr2.sum=curr2.sum-adj[ord[curr.layer]][1]+adj[ord[curr.layer+1]][1];
pq.push(curr2);
}
if(curr.layer+1<=m)
{
curr2=curr;
curr2.layer++;
curr2.lst=1;
curr2.biti=1;
curr2.sum=curr2.sum+adj[ord[curr.layer+1]][1];
pq.push(curr2);
}
if(adj[ord[curr.layer]].size()>curr.lst+1 && curr.biti+1<=y[ord[curr.layer]])
{
curr2=curr;
curr2.lst++;
curr2.biti++;
curr2.sum+=adj[ord[curr.layer]][curr2.lst];
pq.push(curr2);
}
if(adj[ord[curr.layer]].size()>curr.lst+1)
{
curr2=curr;
curr2.sum=curr.sum-adj[ord[curr.layer]][curr.lst]+adj[ord[curr.layer]][curr.lst+1];
curr2.lst++;
pq.push(curr2);
}
}
while(k)
{
k--;
cout<<-1<<'\n';
}
}
return 0;
}
/*
5 2 7
1 5
1 3
2 3
1 6
2 1
1 1
1 1*/
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:58:29: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
58 | if(adj[i].size()<x)
| ~~~~~~~~~~~~~^~
Main.cpp:68:34: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for(long long j=0; j<adj[i].size(); j++)
| ~^~~~~~~~~~~~~~
Main.cpp:85:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | for(i=0; i<ord.size(); i++)
| ~^~~~~~~~~~~
Main.cpp:122:43: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
122 | if(adj[ord[curr.layer]].size()>curr.lst+1 && curr.biti+1<=y[ord[curr.layer]])
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
Main.cpp:130:43: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
130 | if(adj[ord[curr.layer]].size()>curr.lst+1)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
Main.cpp:43:21: warning: unused variable 'minim' [-Wunused-variable]
43 | long long imp=0,minim=inf,poz=m;
| ^~~~~
Main.cpp:43:31: warning: unused variable 'poz' [-Wunused-variable]
43 | long long imp=0,minim=inf,poz=m;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7928 KB |
Output is correct |
2 |
Correct |
4 ms |
7896 KB |
Output is correct |
3 |
Correct |
4 ms |
7896 KB |
Output is correct |
4 |
Correct |
4 ms |
7896 KB |
Output is correct |
5 |
Correct |
4 ms |
7772 KB |
Output is correct |
6 |
Correct |
4 ms |
7772 KB |
Output is correct |
7 |
Correct |
4 ms |
7772 KB |
Output is correct |
8 |
Correct |
5 ms |
7772 KB |
Output is correct |
9 |
Correct |
4 ms |
7260 KB |
Output is correct |
10 |
Correct |
4 ms |
7808 KB |
Output is correct |
11 |
Correct |
4 ms |
7256 KB |
Output is correct |
12 |
Correct |
3 ms |
7516 KB |
Output is correct |
13 |
Correct |
3 ms |
7648 KB |
Output is correct |
14 |
Correct |
5 ms |
7800 KB |
Output is correct |
15 |
Correct |
3 ms |
7516 KB |
Output is correct |
16 |
Correct |
3 ms |
7772 KB |
Output is correct |
17 |
Correct |
5 ms |
7896 KB |
Output is correct |
18 |
Correct |
3 ms |
7260 KB |
Output is correct |
19 |
Correct |
3 ms |
7644 KB |
Output is correct |
20 |
Correct |
4 ms |
7932 KB |
Output is correct |
21 |
Correct |
3 ms |
7256 KB |
Output is correct |
22 |
Correct |
3 ms |
7768 KB |
Output is correct |
23 |
Correct |
4 ms |
7772 KB |
Output is correct |
24 |
Correct |
4 ms |
7516 KB |
Output is correct |
25 |
Correct |
4 ms |
7516 KB |
Output is correct |
26 |
Correct |
5 ms |
7768 KB |
Output is correct |
27 |
Correct |
4 ms |
7772 KB |
Output is correct |
28 |
Correct |
3 ms |
7768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
26840 KB |
Output is correct |
2 |
Correct |
49 ms |
25528 KB |
Output is correct |
3 |
Correct |
54 ms |
26704 KB |
Output is correct |
4 |
Correct |
55 ms |
26804 KB |
Output is correct |
5 |
Correct |
43 ms |
18656 KB |
Output is correct |
6 |
Correct |
42 ms |
17348 KB |
Output is correct |
7 |
Correct |
54 ms |
24924 KB |
Output is correct |
8 |
Correct |
58 ms |
25776 KB |
Output is correct |
9 |
Correct |
12 ms |
8024 KB |
Output is correct |
10 |
Correct |
50 ms |
26488 KB |
Output is correct |
11 |
Correct |
13 ms |
8028 KB |
Output is correct |
12 |
Correct |
23 ms |
8904 KB |
Output is correct |
13 |
Correct |
64 ms |
25788 KB |
Output is correct |
14 |
Correct |
52 ms |
25472 KB |
Output is correct |
15 |
Correct |
12 ms |
8028 KB |
Output is correct |
16 |
Correct |
58 ms |
24792 KB |
Output is correct |
17 |
Correct |
49 ms |
25780 KB |
Output is correct |
18 |
Correct |
17 ms |
8412 KB |
Output is correct |
19 |
Correct |
49 ms |
26552 KB |
Output is correct |
20 |
Correct |
55 ms |
27576 KB |
Output is correct |
21 |
Correct |
16 ms |
8024 KB |
Output is correct |
22 |
Correct |
48 ms |
17388 KB |
Output is correct |
23 |
Correct |
47 ms |
26056 KB |
Output is correct |
24 |
Correct |
12 ms |
8024 KB |
Output is correct |
25 |
Correct |
12 ms |
8024 KB |
Output is correct |
26 |
Correct |
50 ms |
17336 KB |
Output is correct |
27 |
Correct |
42 ms |
18368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7928 KB |
Output is correct |
2 |
Correct |
4 ms |
7896 KB |
Output is correct |
3 |
Correct |
4 ms |
7896 KB |
Output is correct |
4 |
Correct |
4 ms |
7896 KB |
Output is correct |
5 |
Correct |
4 ms |
7772 KB |
Output is correct |
6 |
Correct |
4 ms |
7772 KB |
Output is correct |
7 |
Correct |
4 ms |
7772 KB |
Output is correct |
8 |
Correct |
5 ms |
7772 KB |
Output is correct |
9 |
Correct |
4 ms |
7260 KB |
Output is correct |
10 |
Correct |
4 ms |
7808 KB |
Output is correct |
11 |
Correct |
4 ms |
7256 KB |
Output is correct |
12 |
Correct |
3 ms |
7516 KB |
Output is correct |
13 |
Correct |
3 ms |
7648 KB |
Output is correct |
14 |
Correct |
5 ms |
7800 KB |
Output is correct |
15 |
Correct |
3 ms |
7516 KB |
Output is correct |
16 |
Correct |
3 ms |
7772 KB |
Output is correct |
17 |
Correct |
5 ms |
7896 KB |
Output is correct |
18 |
Correct |
3 ms |
7260 KB |
Output is correct |
19 |
Correct |
3 ms |
7644 KB |
Output is correct |
20 |
Correct |
4 ms |
7932 KB |
Output is correct |
21 |
Correct |
3 ms |
7256 KB |
Output is correct |
22 |
Correct |
3 ms |
7768 KB |
Output is correct |
23 |
Correct |
4 ms |
7772 KB |
Output is correct |
24 |
Correct |
4 ms |
7516 KB |
Output is correct |
25 |
Correct |
4 ms |
7516 KB |
Output is correct |
26 |
Correct |
5 ms |
7768 KB |
Output is correct |
27 |
Correct |
4 ms |
7772 KB |
Output is correct |
28 |
Correct |
3 ms |
7768 KB |
Output is correct |
29 |
Correct |
49 ms |
26840 KB |
Output is correct |
30 |
Correct |
49 ms |
25528 KB |
Output is correct |
31 |
Correct |
54 ms |
26704 KB |
Output is correct |
32 |
Correct |
55 ms |
26804 KB |
Output is correct |
33 |
Correct |
43 ms |
18656 KB |
Output is correct |
34 |
Correct |
42 ms |
17348 KB |
Output is correct |
35 |
Correct |
54 ms |
24924 KB |
Output is correct |
36 |
Correct |
58 ms |
25776 KB |
Output is correct |
37 |
Correct |
12 ms |
8024 KB |
Output is correct |
38 |
Correct |
50 ms |
26488 KB |
Output is correct |
39 |
Correct |
13 ms |
8028 KB |
Output is correct |
40 |
Correct |
23 ms |
8904 KB |
Output is correct |
41 |
Correct |
64 ms |
25788 KB |
Output is correct |
42 |
Correct |
52 ms |
25472 KB |
Output is correct |
43 |
Correct |
12 ms |
8028 KB |
Output is correct |
44 |
Correct |
58 ms |
24792 KB |
Output is correct |
45 |
Correct |
49 ms |
25780 KB |
Output is correct |
46 |
Correct |
17 ms |
8412 KB |
Output is correct |
47 |
Correct |
49 ms |
26552 KB |
Output is correct |
48 |
Correct |
55 ms |
27576 KB |
Output is correct |
49 |
Correct |
16 ms |
8024 KB |
Output is correct |
50 |
Correct |
48 ms |
17388 KB |
Output is correct |
51 |
Correct |
47 ms |
26056 KB |
Output is correct |
52 |
Correct |
12 ms |
8024 KB |
Output is correct |
53 |
Correct |
12 ms |
8024 KB |
Output is correct |
54 |
Correct |
50 ms |
17336 KB |
Output is correct |
55 |
Correct |
42 ms |
18368 KB |
Output is correct |
56 |
Correct |
128 ms |
36668 KB |
Output is correct |
57 |
Correct |
119 ms |
34628 KB |
Output is correct |
58 |
Correct |
138 ms |
34604 KB |
Output is correct |
59 |
Correct |
111 ms |
33116 KB |
Output is correct |
60 |
Correct |
147 ms |
27824 KB |
Output is correct |
61 |
Correct |
121 ms |
34312 KB |
Output is correct |
62 |
Correct |
115 ms |
32928 KB |
Output is correct |
63 |
Correct |
109 ms |
29708 KB |
Output is correct |
64 |
Correct |
54 ms |
13148 KB |
Output is correct |
65 |
Correct |
121 ms |
34872 KB |
Output is correct |
66 |
Correct |
50 ms |
14472 KB |
Output is correct |
67 |
Correct |
43 ms |
11272 KB |
Output is correct |
68 |
Correct |
66 ms |
27064 KB |
Output is correct |
69 |
Correct |
128 ms |
34196 KB |
Output is correct |
70 |
Correct |
13 ms |
8192 KB |
Output is correct |
71 |
Correct |
76 ms |
27064 KB |
Output is correct |
72 |
Correct |
118 ms |
34344 KB |
Output is correct |
73 |
Correct |
12 ms |
7908 KB |
Output is correct |
74 |
Correct |
59 ms |
18044 KB |
Output is correct |
75 |
Correct |
176 ms |
37528 KB |
Output is correct |
76 |
Correct |
13 ms |
7772 KB |
Output is correct |
77 |
Correct |
57 ms |
17092 KB |
Output is correct |
78 |
Correct |
95 ms |
30528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
12740 KB |
Output is correct |
2 |
Correct |
33 ms |
8908 KB |
Output is correct |
3 |
Correct |
13 ms |
8028 KB |
Output is correct |
4 |
Correct |
16 ms |
8032 KB |
Output is correct |
5 |
Correct |
146 ms |
36764 KB |
Output is correct |
6 |
Correct |
157 ms |
35696 KB |
Output is correct |
7 |
Correct |
167 ms |
36664 KB |
Output is correct |
8 |
Correct |
169 ms |
50968 KB |
Output is correct |
9 |
Correct |
155 ms |
35736 KB |
Output is correct |
10 |
Correct |
181 ms |
36468 KB |
Output is correct |
11 |
Correct |
163 ms |
50920 KB |
Output is correct |
12 |
Correct |
140 ms |
33292 KB |
Output is correct |
13 |
Correct |
138 ms |
25320 KB |
Output is correct |
14 |
Correct |
150 ms |
34932 KB |
Output is correct |
15 |
Correct |
148 ms |
35160 KB |
Output is correct |
16 |
Correct |
72 ms |
26020 KB |
Output is correct |
17 |
Correct |
70 ms |
26296 KB |
Output is correct |
18 |
Correct |
161 ms |
52600 KB |
Output is correct |
19 |
Correct |
65 ms |
25276 KB |
Output is correct |
20 |
Correct |
102 ms |
26296 KB |
Output is correct |
21 |
Correct |
155 ms |
35376 KB |
Output is correct |
22 |
Correct |
56 ms |
26032 KB |
Output is correct |
23 |
Correct |
67 ms |
26032 KB |
Output is correct |
24 |
Correct |
164 ms |
37472 KB |
Output is correct |
25 |
Correct |
73 ms |
26040 KB |
Output is correct |
26 |
Correct |
67 ms |
25648 KB |
Output is correct |
27 |
Correct |
186 ms |
31912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7928 KB |
Output is correct |
2 |
Correct |
4 ms |
7896 KB |
Output is correct |
3 |
Correct |
4 ms |
7896 KB |
Output is correct |
4 |
Correct |
4 ms |
7896 KB |
Output is correct |
5 |
Correct |
4 ms |
7772 KB |
Output is correct |
6 |
Correct |
4 ms |
7772 KB |
Output is correct |
7 |
Correct |
4 ms |
7772 KB |
Output is correct |
8 |
Correct |
5 ms |
7772 KB |
Output is correct |
9 |
Correct |
4 ms |
7260 KB |
Output is correct |
10 |
Correct |
4 ms |
7808 KB |
Output is correct |
11 |
Correct |
4 ms |
7256 KB |
Output is correct |
12 |
Correct |
3 ms |
7516 KB |
Output is correct |
13 |
Correct |
3 ms |
7648 KB |
Output is correct |
14 |
Correct |
5 ms |
7800 KB |
Output is correct |
15 |
Correct |
3 ms |
7516 KB |
Output is correct |
16 |
Correct |
3 ms |
7772 KB |
Output is correct |
17 |
Correct |
5 ms |
7896 KB |
Output is correct |
18 |
Correct |
3 ms |
7260 KB |
Output is correct |
19 |
Correct |
3 ms |
7644 KB |
Output is correct |
20 |
Correct |
4 ms |
7932 KB |
Output is correct |
21 |
Correct |
3 ms |
7256 KB |
Output is correct |
22 |
Correct |
3 ms |
7768 KB |
Output is correct |
23 |
Correct |
4 ms |
7772 KB |
Output is correct |
24 |
Correct |
4 ms |
7516 KB |
Output is correct |
25 |
Correct |
4 ms |
7516 KB |
Output is correct |
26 |
Correct |
5 ms |
7768 KB |
Output is correct |
27 |
Correct |
4 ms |
7772 KB |
Output is correct |
28 |
Correct |
3 ms |
7768 KB |
Output is correct |
29 |
Correct |
49 ms |
26840 KB |
Output is correct |
30 |
Correct |
49 ms |
25528 KB |
Output is correct |
31 |
Correct |
54 ms |
26704 KB |
Output is correct |
32 |
Correct |
55 ms |
26804 KB |
Output is correct |
33 |
Correct |
43 ms |
18656 KB |
Output is correct |
34 |
Correct |
42 ms |
17348 KB |
Output is correct |
35 |
Correct |
54 ms |
24924 KB |
Output is correct |
36 |
Correct |
58 ms |
25776 KB |
Output is correct |
37 |
Correct |
12 ms |
8024 KB |
Output is correct |
38 |
Correct |
50 ms |
26488 KB |
Output is correct |
39 |
Correct |
13 ms |
8028 KB |
Output is correct |
40 |
Correct |
23 ms |
8904 KB |
Output is correct |
41 |
Correct |
64 ms |
25788 KB |
Output is correct |
42 |
Correct |
52 ms |
25472 KB |
Output is correct |
43 |
Correct |
12 ms |
8028 KB |
Output is correct |
44 |
Correct |
58 ms |
24792 KB |
Output is correct |
45 |
Correct |
49 ms |
25780 KB |
Output is correct |
46 |
Correct |
17 ms |
8412 KB |
Output is correct |
47 |
Correct |
49 ms |
26552 KB |
Output is correct |
48 |
Correct |
55 ms |
27576 KB |
Output is correct |
49 |
Correct |
16 ms |
8024 KB |
Output is correct |
50 |
Correct |
48 ms |
17388 KB |
Output is correct |
51 |
Correct |
47 ms |
26056 KB |
Output is correct |
52 |
Correct |
12 ms |
8024 KB |
Output is correct |
53 |
Correct |
12 ms |
8024 KB |
Output is correct |
54 |
Correct |
50 ms |
17336 KB |
Output is correct |
55 |
Correct |
42 ms |
18368 KB |
Output is correct |
56 |
Correct |
128 ms |
36668 KB |
Output is correct |
57 |
Correct |
119 ms |
34628 KB |
Output is correct |
58 |
Correct |
138 ms |
34604 KB |
Output is correct |
59 |
Correct |
111 ms |
33116 KB |
Output is correct |
60 |
Correct |
147 ms |
27824 KB |
Output is correct |
61 |
Correct |
121 ms |
34312 KB |
Output is correct |
62 |
Correct |
115 ms |
32928 KB |
Output is correct |
63 |
Correct |
109 ms |
29708 KB |
Output is correct |
64 |
Correct |
54 ms |
13148 KB |
Output is correct |
65 |
Correct |
121 ms |
34872 KB |
Output is correct |
66 |
Correct |
50 ms |
14472 KB |
Output is correct |
67 |
Correct |
43 ms |
11272 KB |
Output is correct |
68 |
Correct |
66 ms |
27064 KB |
Output is correct |
69 |
Correct |
128 ms |
34196 KB |
Output is correct |
70 |
Correct |
13 ms |
8192 KB |
Output is correct |
71 |
Correct |
76 ms |
27064 KB |
Output is correct |
72 |
Correct |
118 ms |
34344 KB |
Output is correct |
73 |
Correct |
12 ms |
7908 KB |
Output is correct |
74 |
Correct |
59 ms |
18044 KB |
Output is correct |
75 |
Correct |
176 ms |
37528 KB |
Output is correct |
76 |
Correct |
13 ms |
7772 KB |
Output is correct |
77 |
Correct |
57 ms |
17092 KB |
Output is correct |
78 |
Correct |
95 ms |
30528 KB |
Output is correct |
79 |
Correct |
38 ms |
12740 KB |
Output is correct |
80 |
Correct |
33 ms |
8908 KB |
Output is correct |
81 |
Correct |
13 ms |
8028 KB |
Output is correct |
82 |
Correct |
16 ms |
8032 KB |
Output is correct |
83 |
Correct |
146 ms |
36764 KB |
Output is correct |
84 |
Correct |
157 ms |
35696 KB |
Output is correct |
85 |
Correct |
167 ms |
36664 KB |
Output is correct |
86 |
Correct |
169 ms |
50968 KB |
Output is correct |
87 |
Correct |
155 ms |
35736 KB |
Output is correct |
88 |
Correct |
181 ms |
36468 KB |
Output is correct |
89 |
Correct |
163 ms |
50920 KB |
Output is correct |
90 |
Correct |
140 ms |
33292 KB |
Output is correct |
91 |
Correct |
138 ms |
25320 KB |
Output is correct |
92 |
Correct |
150 ms |
34932 KB |
Output is correct |
93 |
Correct |
148 ms |
35160 KB |
Output is correct |
94 |
Correct |
72 ms |
26020 KB |
Output is correct |
95 |
Correct |
70 ms |
26296 KB |
Output is correct |
96 |
Correct |
161 ms |
52600 KB |
Output is correct |
97 |
Correct |
65 ms |
25276 KB |
Output is correct |
98 |
Correct |
102 ms |
26296 KB |
Output is correct |
99 |
Correct |
155 ms |
35376 KB |
Output is correct |
100 |
Correct |
56 ms |
26032 KB |
Output is correct |
101 |
Correct |
67 ms |
26032 KB |
Output is correct |
102 |
Correct |
164 ms |
37472 KB |
Output is correct |
103 |
Correct |
73 ms |
26040 KB |
Output is correct |
104 |
Correct |
67 ms |
25648 KB |
Output is correct |
105 |
Correct |
186 ms |
31912 KB |
Output is correct |
106 |
Incorrect |
39 ms |
13520 KB |
Output isn't correct |
107 |
Halted |
0 ms |
0 KB |
- |