This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |