#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
struct node
{
long long layer,sum,lst;
};
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];
int main()
{
long long n,m,k,i,a,b,x,y;
long long sum=0;
cin>>n>>m>>k;
for(i=1;i<=n;i++)
{
cin>>a>>b;
adj[a].push_back(b);
}
for(i=1;i<=m;i++)
{
cin>>x>>y;
sort(adj[i].begin(),adj[i].end());
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());
// cout<<sum<<'\n';
node curr,curr2;
pq.push({1,0,0});
while(pq.size() && k)
{
curr=pq.top();
pq.pop();
if(curr.layer==m+1)
{
k--;
cout<<curr.sum+sum<<'\n';
}
else
{
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:34:29: 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]
34 | for(long long j=0;j<adj[i].size();j++)
| ~^~~~~~~~~~~~~~
Main.cpp:54: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]
54 | if(curr.lst+1<adj[curr.layer].size())
| ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
453 ms |
54924 KB |
Output is correct |
2 |
Correct |
185 ms |
30132 KB |
Output is correct |
3 |
Correct |
412 ms |
55352 KB |
Output is correct |
4 |
Correct |
93 ms |
13044 KB |
Output is correct |
5 |
Correct |
307 ms |
30384 KB |
Output is correct |
6 |
Correct |
219 ms |
55720 KB |
Output is correct |
7 |
Correct |
69 ms |
19128 KB |
Output is correct |
8 |
Correct |
7 ms |
5672 KB |
Output is correct |
9 |
Correct |
4 ms |
5212 KB |
Output is correct |
10 |
Correct |
199 ms |
30396 KB |
Output is correct |
11 |
Runtime error |
8 ms |
10076 KB |
Execution killed with signal 11 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4034 ms |
399628 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
453 ms |
54924 KB |
Output is correct |
2 |
Correct |
185 ms |
30132 KB |
Output is correct |
3 |
Correct |
412 ms |
55352 KB |
Output is correct |
4 |
Correct |
93 ms |
13044 KB |
Output is correct |
5 |
Correct |
307 ms |
30384 KB |
Output is correct |
6 |
Correct |
219 ms |
55720 KB |
Output is correct |
7 |
Correct |
69 ms |
19128 KB |
Output is correct |
8 |
Correct |
7 ms |
5672 KB |
Output is correct |
9 |
Correct |
4 ms |
5212 KB |
Output is correct |
10 |
Correct |
199 ms |
30396 KB |
Output is correct |
11 |
Runtime error |
8 ms |
10076 KB |
Execution killed with signal 11 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
6 ms |
10072 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
453 ms |
54924 KB |
Output is correct |
2 |
Correct |
185 ms |
30132 KB |
Output is correct |
3 |
Correct |
412 ms |
55352 KB |
Output is correct |
4 |
Correct |
93 ms |
13044 KB |
Output is correct |
5 |
Correct |
307 ms |
30384 KB |
Output is correct |
6 |
Correct |
219 ms |
55720 KB |
Output is correct |
7 |
Correct |
69 ms |
19128 KB |
Output is correct |
8 |
Correct |
7 ms |
5672 KB |
Output is correct |
9 |
Correct |
4 ms |
5212 KB |
Output is correct |
10 |
Correct |
199 ms |
30396 KB |
Output is correct |
11 |
Runtime error |
8 ms |
10076 KB |
Execution killed with signal 11 |
12 |
Halted |
0 ms |
0 KB |
- |