CodeForces 1144 C

http://codeforces.com/problemset/problem/1144/C

Two integer sequences existed initially — one of them was strictly increasing, and the other one — strictly decreasing.

Strictly increasing sequence is a sequence of integers [x1<x2<⋯<xk][x1<x2<⋯<xk] . And strictly decreasing sequence is a sequence of integers [y1>y2>⋯>yl][y1>y2>⋯>yl] . Note that the empty sequence and the sequence consisting of one element can be considered as increasing or decreasing.

They were merged into one sequence aa . After that sequence aa got shuffled. For example, some of the possible resulting sequences aa for an increasing sequence [1,3,4][1,3,4] and a decreasing sequence [10,4,2][10,4,2] are sequences [1,2,3,4,4,10][1,2,3,4,4,10] or [4,2,1,10,4,3][4,2,1,10,4,3] .

This shuffled sequence aa is given in the input.

Your task is to find any two suitable initial sequences. One of them should be strictly increasing and the other one — strictly decreasing. Note that the empty sequence and the sequence consisting of one element can be considered as increasing or decreasing.

If there is a contradiction in the input and it is impossible to split the given sequence aa to increasing and decreasing sequences, print "NO".

Input

The first line of the input contains one integer nn (1≤n≤2⋅1051≤n≤2⋅105 ) — the number of elements in aa .

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤2⋅1050≤ai≤2⋅105 ), where aiai is the ii -th element of aa .

Output

If there is a contradiction in the input and it is impossible to split the given sequence aa to increasing and decreasing sequences, print "NO" in the first line.

Otherwise print "YES" in the first line and any two suitable sequences. Note that the empty sequence and the sequence consisting of one element can be considered as increasing or decreasing.

In the second line print nini — the number of elements in the strictly increasing sequence. nini can be zero, in this case the increasing sequence is empty.

In the third line print nini integers inc1,inc2,…,incniinc1,inc2,…,incni in the increasing order of its values (inc1<inc2<⋯<incniinc1<inc2<⋯<incni ) — the strictly increasing sequence itself. You can keep this line empty if ni=0ni=0 (or just print the empty line).

In the fourth line print ndnd — the number of elements in the strictly decreasing sequence. ndnd can be zero, in this case the decreasing sequence is empty.

In the fifth line print ndnd integers dec1,dec2,…,decnddec1,dec2,…,decnd in the decreasing order of its values (dec1>dec2>⋯>decnddec1>dec2>⋯>decnd ) — the strictly decreasing sequence itself. You can keep this line empty if nd=0nd=0 (or just print the empty line).

ni+ndni+nd should be equal to nn and the union of printed sequences should be a permutation of the given sequence (in case of "YES" answer).

题目大意:给出一个序列,让你把它分成两个序列,一个严格递增,一个严格递减,两个序列的长度之和为n,(某一个的长度可以为0) 如果可以输出"YES"和分组方案,否则输出"NO"。

思路:出现3次及以上必定不满足题意。否则对原序列进行排序,出现两次的数字两个序列各放一个,否则均放入升序。(或者降序)

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;

int a[200005];
int b[200005];//升序
int c[200005];//降序
int vis[200005];
int len1=0,len2=0;
int n;

int main()
{
	scanf("%d",&n);
	int flag=0;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(++vis[a[i]]>2)
			flag=1;
	}
	if(flag)
		printf("NO\n");
	else
	{
		sort(a,a+n);
		flag=0;
		b[len1++]=a[0];
		for(int i=1;i<n;i++)
		{
			if(a[i]==a[i-1])//出现两次的数字 两个序列各放一个
				c[len2++]=a[i];
			else        //其他的均放进升序序列
				b[len1++]=a[i];
			if(len2>=2&&c[len2-1]<c[len2-2])  //不符合题意的情况
				flag=1;
		}
		if(flag)
			printf("NO\n");
		else
		{
			printf("YES\n");
			printf("%d\n",len1);
			for(int i=0;i<len1;i++)
				printf("%d ",b[i]);
			printf("\n");
			printf("%d\n",len2);
			for(int i=len2-1;i>=0;i--)//逆序打印c
				printf("%d ",c[i]);
			printf("\n");
		}
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值