#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n;int m;int K;
vector<int>e[500005];
signed main(){
cin>>n>>m>>K;
for(int i=1;i<=n;i++){
int a;int c;
cin>>a>>c;
e[a].push_back(c);
}
for(int i=1;i<=m;i++){
int a;
cin>>a;
cin>>a;
}
for(int i=1;i<=m;i++){
sort(e[i].begin(),e[i].end());
}
priority_queue<pair<int,pair<int,int>>>pq;
{
int S=0;
for(int i=1;i<=m;i++){
if(e[i].size()==0){
for(int j=1;j<=K;j++){
cout<<"-1\n";
}return 0;
}
S+=e[i][0];
}
pq.push({-S,{0,-1}});
}
while(K--){
if(pq.size()==0){
for(int i=1;i<=K+1;i++){
cout<<"-1\n";
}
return 0;
}
int nwv=pq.top().first;
cout<<-nwv<<"\n";
int nw=pq.top().second.first;
int nww=pq.top().second.second;
// cout<<nw<<" "<<nww<<"\n";
pq.pop();
nwv=-nwv;
if(nw>=1){
if(e[nw].size()>nww+1){
pq.push({-(nwv+-e[nw][nww]+e[nw][nww+1]),{nw,nww+1}});
}
}
for(int j=nw+1;j<=m;j++){
if(e[j].size()>=2){
pq.push({-(nwv+e[j][1]-e[j][0]),{j,1}});
}
}
}
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:53:24: 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]
53 | if(e[nw].size()>nww+1){
| ~~~~~~~~~~~~^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
62388 KB |
Output is correct |
2 |
Correct |
31 ms |
38040 KB |
Output is correct |
3 |
Correct |
54 ms |
63008 KB |
Output is correct |
4 |
Correct |
13 ms |
18512 KB |
Output is correct |
5 |
Correct |
36 ms |
38508 KB |
Output is correct |
6 |
Correct |
46 ms |
63376 KB |
Output is correct |
7 |
Correct |
18 ms |
26568 KB |
Output is correct |
8 |
Correct |
7 ms |
12836 KB |
Output is correct |
9 |
Correct |
6 ms |
12120 KB |
Output is correct |
10 |
Correct |
28 ms |
37500 KB |
Output is correct |
11 |
Correct |
6 ms |
12196 KB |
Output is correct |
12 |
Correct |
4 ms |
12124 KB |
Output is correct |
13 |
Correct |
8 ms |
16132 KB |
Output is correct |
14 |
Correct |
53 ms |
62352 KB |
Output is correct |
15 |
Correct |
4 ms |
12124 KB |
Output is correct |
16 |
Correct |
6 ms |
12576 KB |
Output is correct |
17 |
Correct |
13 ms |
19408 KB |
Output is correct |
18 |
Correct |
4 ms |
12376 KB |
Output is correct |
19 |
Correct |
6 ms |
13780 KB |
Output is correct |
20 |
Correct |
38 ms |
38596 KB |
Output is correct |
21 |
Correct |
4 ms |
12124 KB |
Output is correct |
22 |
Correct |
4 ms |
12124 KB |
Output is correct |
23 |
Correct |
7 ms |
12756 KB |
Output is correct |
24 |
Correct |
7 ms |
12380 KB |
Output is correct |
25 |
Correct |
6 ms |
12380 KB |
Output is correct |
26 |
Correct |
27 ms |
37308 KB |
Output is correct |
27 |
Correct |
13 ms |
18636 KB |
Output is correct |
28 |
Correct |
6 ms |
13156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1480 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
62388 KB |
Output is correct |
2 |
Correct |
31 ms |
38040 KB |
Output is correct |
3 |
Correct |
54 ms |
63008 KB |
Output is correct |
4 |
Correct |
13 ms |
18512 KB |
Output is correct |
5 |
Correct |
36 ms |
38508 KB |
Output is correct |
6 |
Correct |
46 ms |
63376 KB |
Output is correct |
7 |
Correct |
18 ms |
26568 KB |
Output is correct |
8 |
Correct |
7 ms |
12836 KB |
Output is correct |
9 |
Correct |
6 ms |
12120 KB |
Output is correct |
10 |
Correct |
28 ms |
37500 KB |
Output is correct |
11 |
Correct |
6 ms |
12196 KB |
Output is correct |
12 |
Correct |
4 ms |
12124 KB |
Output is correct |
13 |
Correct |
8 ms |
16132 KB |
Output is correct |
14 |
Correct |
53 ms |
62352 KB |
Output is correct |
15 |
Correct |
4 ms |
12124 KB |
Output is correct |
16 |
Correct |
6 ms |
12576 KB |
Output is correct |
17 |
Correct |
13 ms |
19408 KB |
Output is correct |
18 |
Correct |
4 ms |
12376 KB |
Output is correct |
19 |
Correct |
6 ms |
13780 KB |
Output is correct |
20 |
Correct |
38 ms |
38596 KB |
Output is correct |
21 |
Correct |
4 ms |
12124 KB |
Output is correct |
22 |
Correct |
4 ms |
12124 KB |
Output is correct |
23 |
Correct |
7 ms |
12756 KB |
Output is correct |
24 |
Correct |
7 ms |
12380 KB |
Output is correct |
25 |
Correct |
6 ms |
12380 KB |
Output is correct |
26 |
Correct |
27 ms |
37308 KB |
Output is correct |
27 |
Correct |
13 ms |
18636 KB |
Output is correct |
28 |
Correct |
6 ms |
13156 KB |
Output is correct |
29 |
Runtime error |
1480 ms |
1048576 KB |
Execution killed with signal 9 |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
12632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
62388 KB |
Output is correct |
2 |
Correct |
31 ms |
38040 KB |
Output is correct |
3 |
Correct |
54 ms |
63008 KB |
Output is correct |
4 |
Correct |
13 ms |
18512 KB |
Output is correct |
5 |
Correct |
36 ms |
38508 KB |
Output is correct |
6 |
Correct |
46 ms |
63376 KB |
Output is correct |
7 |
Correct |
18 ms |
26568 KB |
Output is correct |
8 |
Correct |
7 ms |
12836 KB |
Output is correct |
9 |
Correct |
6 ms |
12120 KB |
Output is correct |
10 |
Correct |
28 ms |
37500 KB |
Output is correct |
11 |
Correct |
6 ms |
12196 KB |
Output is correct |
12 |
Correct |
4 ms |
12124 KB |
Output is correct |
13 |
Correct |
8 ms |
16132 KB |
Output is correct |
14 |
Correct |
53 ms |
62352 KB |
Output is correct |
15 |
Correct |
4 ms |
12124 KB |
Output is correct |
16 |
Correct |
6 ms |
12576 KB |
Output is correct |
17 |
Correct |
13 ms |
19408 KB |
Output is correct |
18 |
Correct |
4 ms |
12376 KB |
Output is correct |
19 |
Correct |
6 ms |
13780 KB |
Output is correct |
20 |
Correct |
38 ms |
38596 KB |
Output is correct |
21 |
Correct |
4 ms |
12124 KB |
Output is correct |
22 |
Correct |
4 ms |
12124 KB |
Output is correct |
23 |
Correct |
7 ms |
12756 KB |
Output is correct |
24 |
Correct |
7 ms |
12380 KB |
Output is correct |
25 |
Correct |
6 ms |
12380 KB |
Output is correct |
26 |
Correct |
27 ms |
37308 KB |
Output is correct |
27 |
Correct |
13 ms |
18636 KB |
Output is correct |
28 |
Correct |
6 ms |
13156 KB |
Output is correct |
29 |
Runtime error |
1480 ms |
1048576 KB |
Execution killed with signal 9 |
30 |
Halted |
0 ms |
0 KB |
- |