-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path56849212.cpp
62 lines (61 loc) · 1.25 KB
/
56849212.cpp
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
bool cmp(int a,int b);
int main()
{
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
sort(arr,arr+n);
vector<int> increasing,decreasing;
for(int i=0;i<n-2;i++)
{
if(arr[i]==arr[i+1] && arr[i]==arr[i+2])
{
cout<<"NO"<<endl;
return 0 ;
}
}
for(int i=0;i<n;i++)
{
if(i!=n-1)
{
if(arr[i]==arr[i+1])
{
increasing.push_back(arr[i]);
decreasing.push_back(arr[i+1]);
i++;
}
else
{
increasing.push_back(arr[i]);
}
}
else
{
increasing.push_back(arr[i]);
}
}
sort(increasing.begin(),increasing.end());
sort(decreasing.begin(),decreasing.end(),cmp);
cout<<"YES"<<endl;
cout<<increasing.size()<<endl;
for(int i=0;i<increasing.size();i++)
cout<<increasing[i]<<" ";
cout<<endl;
cout<<decreasing.size()<<endl;
for(int i=0;i<decreasing.size();i++)
cout<<decreasing[i]<<" ";
cout<<endl;
return 0;
}
bool cmp(int a,int b)
{
return a>b;
}