-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10972.cpp
More file actions
43 lines (42 loc) · 782 Bytes
/
10972.cpp
File metadata and controls
43 lines (42 loc) · 782 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
39
40
41
42
43
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,prev,x;
cin>>n;
vector<int> d(n,0);
for(int i=0;i<n;i++){
cin>>d[i];
}
int idx=-1;
for(int i=0;i<n-1;i++){
if(d[i]<d[i+1]){
idx=i;
}
}
if(idx==-1){
cout<<"-1";
return 0;
}
int m=10001;
for(int i=idx+1;i<n;i++){
if(d[idx]<d[i])
m = min(m,d[i]);
}
vector<int> a;
for(int i=idx;i<n;i++){
if(d[i]!=m)
a.push_back(d[i]);
}
sort(a.begin(),a.end());
for(int i=0;i<idx;i++){
cout<<d[i]<<" ";
}
cout<<m<<" ";
for(int x : a){
cout<<x<<" ";
}
}