#include <bits/stdc++.h>
using namespace std;
bool s = 1;
priority_queue<long long> heap[9];
vector<long long> ans;
long long n,p,v;
int main(){
cin >> n;
for(int i = 1;i <= n;i++){
cin >> p >> v;
heap[p].push(-v);
}
if(heap[5].size() + heap[6].size() != 1 || heap[7].size() + heap[8].size() != 1)
goto CANNOT;
if(heap[5].size()){
s ^= 1;// ->
ans.push_back(-heap[5].top());
}
else{
ans.push_back(-heap[6].top());
}
while(heap[1].size() + heap[4].size()){
if(s == 1){
if(heap[1].size() == 0)
goto CANNOT;
ans.push_back(-heap[1].top());
heap[1].pop();
} else{
if(heap[4].size() == 0)
goto CANNOT;
ans.push_back(-heap[4].top());
heap[4].pop();
}
s ^= 1;
}
if((s == 0? heap[8].size() == 0 : heap[7].size() == 0) )
goto CANNOT;
ans.push_back(-(heap[8].size() ? heap[8].top() : heap[7].top() ) );
for(int e : ans)
cout << e << " ";
return 0;
CANNOT: ;
cout << -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Incorrect |
5 ms |
256 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
3768 KB |
Output is correct |
2 |
Correct |
97 ms |
3352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
3664 KB |
Output is correct |
2 |
Correct |
104 ms |
3180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
2568 KB |
Output is correct |
2 |
Incorrect |
82 ms |
2316 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
2268 KB |
Output is correct |
2 |
Incorrect |
75 ms |
2412 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
77 ms |
2204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
76 ms |
2416 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
84 ms |
2832 KB |
Output is correct |
2 |
Incorrect |
94 ms |
3312 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
104 ms |
3480 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
89 ms |
3616 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
99 ms |
3436 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
89 ms |
2896 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
90 ms |
3128 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |