-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path652B-Zsort.cpp
More file actions
38 lines (32 loc) · 821 Bytes
/
652B-Zsort.cpp
File metadata and controls
38 lines (32 loc) · 821 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <iterator>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n;
string str;
cin>>n;
cin.ignore();
getline(cin, str);
stringstream ss(str);
auto start = istream_iterator<int>(ss);
auto end= istream_iterator<int>();
vector<int> array(start, end);
sort(array.begin(),array.end());
vector<int> arrayZsorted; //[1, 2, 2, 1] -> []
for(int i=0; 2*i < n; i++) {
if ( i>0 && array[n-i] < array[i] ) {
cout<<"Impossible"<<endl;
return 0;
}
arrayZsorted.push_back(array[i]);
arrayZsorted.push_back(array[n-i-1]);
}
for(int i=0; i<n-1; i++) {
cout<<arrayZsorted[i]<<" ";
}
cout<<arrayZsorted[n-1]<<endl;
}