#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
//ifstream cin("a.in");
//ofstream cout("a.out");
struct node
{
long long layer,sum,lst;
};
struct cmp
{
bool operator()(node a,node b)
{
if(a.sum==b.sum)
{
return a.layer<b.layer;
}
return a.sum>b.sum;
}
};
priority_queue<node,vector<node>,cmp>pq;
vector<long long >arr;
vector<long long >adj[200005];
int main()
{
long long n,m,k,i,a,b,x,y;
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);
}
int imp=0;
for(i=1; i<=m; i++)
{
cin>>x>>y;
sort(adj[i].begin(),adj[i].end());
if(adj[i].size()==0)
{
imp=1;
}
else
{
long long vkuk=adj[i][0];
sum+=adj[i][0];
for(long long j=0; j<adj[i].size(); j++)
{
adj[i][j]-=vkuk;
}
}
}
// sort(arr.begin(),arr.end());
if(imp==1)
{
cout<<-1<<'\n';
}
else
{
cout<<sum<<'\n';
}
k--;
node curr,curr2;
pq.push({1,0,0});
while(pq.size() && k && imp==0)
{
curr=pq.top();
pq.pop();
if(curr.lst!=0)
{
k--;
cout<<curr.sum+sum<<'\n';
}
if(curr.layer!=m+1)
{
if(curr.lst+1<adj[curr.layer].size())
{
curr2=curr;
curr2.lst++;
curr2.sum=curr2.sum-adj[curr.layer][curr.lst]+adj[curr.layer][curr.lst+1];
pq.push(curr2);
}
curr2=curr;
curr2.lst=0;
curr2.layer++;
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:52: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]
52 | for(long long j=0; j<adj[i].size(); j++)
| ~^~~~~~~~~~~~~~
Main.cpp:81:26: 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]
81 | if(curr.lst+1<adj[curr.layer].size())
| ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
446 ms |
55716 KB |
Output is correct |
2 |
Correct |
183 ms |
30636 KB |
Output is correct |
3 |
Correct |
418 ms |
55972 KB |
Output is correct |
4 |
Correct |
89 ms |
12736 KB |
Output is correct |
5 |
Correct |
303 ms |
31148 KB |
Output is correct |
6 |
Correct |
215 ms |
54952 KB |
Output is correct |
7 |
Correct |
64 ms |
17600 KB |
Output is correct |
8 |
Correct |
6 ms |
5668 KB |
Output is correct |
9 |
Correct |
3 ms |
5212 KB |
Output is correct |
10 |
Correct |
196 ms |
30760 KB |
Output is correct |
11 |
Correct |
3 ms |
5212 KB |
Output is correct |
12 |
Correct |
3 ms |
5212 KB |
Output is correct |
13 |
Correct |
22 ms |
8400 KB |
Output is correct |
14 |
Correct |
391 ms |
54952 KB |
Output is correct |
15 |
Correct |
3 ms |
5208 KB |
Output is correct |
16 |
Correct |
6 ms |
5660 KB |
Output is correct |
17 |
Correct |
100 ms |
12056 KB |
Output is correct |
18 |
Correct |
7 ms |
5212 KB |
Output is correct |
19 |
Correct |
17 ms |
6864 KB |
Output is correct |
20 |
Correct |
341 ms |
31660 KB |
Output is correct |
21 |
Correct |
2 ms |
4956 KB |
Output is correct |
22 |
Correct |
2 ms |
5212 KB |
Output is correct |
23 |
Correct |
5 ms |
5672 KB |
Output is correct |
24 |
Correct |
3 ms |
5288 KB |
Output is correct |
25 |
Correct |
5 ms |
5212 KB |
Output is correct |
26 |
Correct |
179 ms |
31324 KB |
Output is correct |
27 |
Correct |
119 ms |
13552 KB |
Output is correct |
28 |
Correct |
7 ms |
5988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4065 ms |
399548 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
446 ms |
55716 KB |
Output is correct |
2 |
Correct |
183 ms |
30636 KB |
Output is correct |
3 |
Correct |
418 ms |
55972 KB |
Output is correct |
4 |
Correct |
89 ms |
12736 KB |
Output is correct |
5 |
Correct |
303 ms |
31148 KB |
Output is correct |
6 |
Correct |
215 ms |
54952 KB |
Output is correct |
7 |
Correct |
64 ms |
17600 KB |
Output is correct |
8 |
Correct |
6 ms |
5668 KB |
Output is correct |
9 |
Correct |
3 ms |
5212 KB |
Output is correct |
10 |
Correct |
196 ms |
30760 KB |
Output is correct |
11 |
Correct |
3 ms |
5212 KB |
Output is correct |
12 |
Correct |
3 ms |
5212 KB |
Output is correct |
13 |
Correct |
22 ms |
8400 KB |
Output is correct |
14 |
Correct |
391 ms |
54952 KB |
Output is correct |
15 |
Correct |
3 ms |
5208 KB |
Output is correct |
16 |
Correct |
6 ms |
5660 KB |
Output is correct |
17 |
Correct |
100 ms |
12056 KB |
Output is correct |
18 |
Correct |
7 ms |
5212 KB |
Output is correct |
19 |
Correct |
17 ms |
6864 KB |
Output is correct |
20 |
Correct |
341 ms |
31660 KB |
Output is correct |
21 |
Correct |
2 ms |
4956 KB |
Output is correct |
22 |
Correct |
2 ms |
5212 KB |
Output is correct |
23 |
Correct |
5 ms |
5672 KB |
Output is correct |
24 |
Correct |
3 ms |
5288 KB |
Output is correct |
25 |
Correct |
5 ms |
5212 KB |
Output is correct |
26 |
Correct |
179 ms |
31324 KB |
Output is correct |
27 |
Correct |
119 ms |
13552 KB |
Output is correct |
28 |
Correct |
7 ms |
5988 KB |
Output is correct |
29 |
Execution timed out |
4065 ms |
399548 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
5720 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
446 ms |
55716 KB |
Output is correct |
2 |
Correct |
183 ms |
30636 KB |
Output is correct |
3 |
Correct |
418 ms |
55972 KB |
Output is correct |
4 |
Correct |
89 ms |
12736 KB |
Output is correct |
5 |
Correct |
303 ms |
31148 KB |
Output is correct |
6 |
Correct |
215 ms |
54952 KB |
Output is correct |
7 |
Correct |
64 ms |
17600 KB |
Output is correct |
8 |
Correct |
6 ms |
5668 KB |
Output is correct |
9 |
Correct |
3 ms |
5212 KB |
Output is correct |
10 |
Correct |
196 ms |
30760 KB |
Output is correct |
11 |
Correct |
3 ms |
5212 KB |
Output is correct |
12 |
Correct |
3 ms |
5212 KB |
Output is correct |
13 |
Correct |
22 ms |
8400 KB |
Output is correct |
14 |
Correct |
391 ms |
54952 KB |
Output is correct |
15 |
Correct |
3 ms |
5208 KB |
Output is correct |
16 |
Correct |
6 ms |
5660 KB |
Output is correct |
17 |
Correct |
100 ms |
12056 KB |
Output is correct |
18 |
Correct |
7 ms |
5212 KB |
Output is correct |
19 |
Correct |
17 ms |
6864 KB |
Output is correct |
20 |
Correct |
341 ms |
31660 KB |
Output is correct |
21 |
Correct |
2 ms |
4956 KB |
Output is correct |
22 |
Correct |
2 ms |
5212 KB |
Output is correct |
23 |
Correct |
5 ms |
5672 KB |
Output is correct |
24 |
Correct |
3 ms |
5288 KB |
Output is correct |
25 |
Correct |
5 ms |
5212 KB |
Output is correct |
26 |
Correct |
179 ms |
31324 KB |
Output is correct |
27 |
Correct |
119 ms |
13552 KB |
Output is correct |
28 |
Correct |
7 ms |
5988 KB |
Output is correct |
29 |
Execution timed out |
4065 ms |
399548 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |