#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fir first
#define sec second
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int32_t main(){
int n,one=0,four=0,l,r,l1,r1;
cin >> n;
vector<int> a,b;
while(n--){
int x,y;
cin >> x >> y;
if(x==5) l=1,l1=y;
if(x==6) l=0,l1=y;
if(x==7) r=1,r1=y;
if(x==8) r=0,r1=y;
if(x==1)
one++,a.pb(y);
if(x==4)
four++,b.pb(y);
}
sort(a.begin(),a.end());
sort(b.begin(),b.end());
cout << l1 << " ";
if(l!=r){
if(one!=four){
cout << -1;
return 0;
}
int c,k=1;
if(l==1)
c=0;
else
c=1;
for(int i=0;i<a.size();i++){
if(c)
cout << a[i] << " ";
else
cout << b[i] << " ";
if(k)
i--;
k^=1;
c^=1;
}
}
else if(l==1){
if(one!=four-1){
cout << -1;
return 0;
}
int c=0,k=1;
for(int i=0;i<b.size();i++){
if(c)
cout << a[i] << " ";
else
cout << b[i] << " ";
if(i==b.size()-1)
break;
if(k)
i--;
k^=1;
c^=1;
}
}
else if(l==0){
if(one!=four+1){
cout << -1;
return 0;
}
int c=1,k=1;
for(int i=0;i<a.size();i++){
if(c)
cout << a[i] << " ";
else
cout << b[i] << " ";
if(i==a.size()-1)
break;
if(k)
i--;
k^=1;
c^=1;
}
}
cout << r1;
return 0;
}
Compilation message
slagalica.cpp: In function 'int32_t main()':
slagalica.cpp:37:22: 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]
37 | for(int i=0;i<a.size();i++){
| ~^~~~~~~~~
slagalica.cpp:55:22: 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]
55 | for(int i=0;i<b.size();i++){
| ~^~~~~~~~~
slagalica.cpp:60:17: 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]
60 | if(i==b.size()-1)
| ~^~~~~~~~~~~~
slagalica.cpp:74:22: 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]
74 | for(int i=0;i<a.size();i++){
| ~^~~~~~~~~
slagalica.cpp:79:17: 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]
79 | if(i==a.size()-1)
| ~^~~~~~~~~~~~
slagalica.cpp:27:5: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
27 | if(l!=r){
| ^~
slagalica.cpp:48:10: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
48 | else if(l==1){
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
296 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
296 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
2992 KB |
Output is correct |
2 |
Incorrect |
58 ms |
2320 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
2844 KB |
Output is correct |
2 |
Incorrect |
52 ms |
2168 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
69 ms |
1412 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
43 ms |
1356 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
45 ms |
1156 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
48 ms |
1248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
58 ms |
1868 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
73 ms |
2584 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
65 ms |
2468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
62 ms |
2304 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
61 ms |
2152 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
66 ms |
2248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |