Time Limit:3000MS | Memory Limit:Unknown | 64bit IO Format:%lld & %llu |
Description






Input
The input file contains several test cases, each of them as described below. The first line of the input contains the single integer number n ( 1



Output
For each test case, the first line of the output must contain `` Yes'' if the trading session with specified volumes is possible and `` No'' otherwise. In the former option a second line must contain n numbers -- bi .Sample Input
4 1 2 3 3 4 1 2 3 4
Sample Output
No Yes 1 -1 -1 1
Source
Root :: AOAPC II: Beginning Algorithm Contests (Second Edition) (Rujia Liu) :: Chapter 8. Algorithm Design :: Exercises
排序之后贪心瞎搞。。。
/*************************************************************************
> File Name: c.cpp
> Author: acvcla
> QQ:
> Mail: acvcla@gmail.com
> Created Time: 2014年10月11日 星期六 08时42分28秒
************************************************************************/
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<cstring>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<cstdlib>
#include<ctime>
#include<set>
#include<math.h>
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 10;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
int A[maxn],cnt[maxn],f[maxn];
std::vector<int> v;
int main(){
int n;
while(~scanf("%d",&n)&&n){
memset(cnt,0,sizeof(cnt));
memset(f,0,sizeof f);
v.clear();
LL sum=0;
LL M=0;
for(int i=1;i<=n;i++){
scanf("%d",A+i);
if(A[i]>M)M=A[i];
sum+=A[i];
cnt[A[i]]++;
}
if(sum&1){
puts("No");
continue;
}
sum/=2;
bool ok=false;
for(int i=M;!ok&&i>=1;i--){
f[i]=min((LL)cnt[i],sum/i);
sum-=(LL)f[i]*i;
if(sum==0){
ok=true;
break;
}
}
if(!ok){
puts("No");
}else{
puts("Yes");
for(int i=1;i<=n;i++){
if(i==1){
if(f[A[i]]>0){
printf("1");
f[A[i]]--;
}
else printf("-1");
}
else{
if(f[A[i]]>0){
printf(" 1");
f[A[i]]--;
}
else printf(" -1");
}
}
puts("");
}
}
return 0;
}