Description ![]() Most financial institutions had become insolvent during financial crisis and went bankrupt or were bought by larger institutions, usually by banks. By the end of financial crisis of all the financial institutions only two banks still continue to operate. Financial markets had remained closed throughout the crisis and now regulators are gradually opening them. To prevent speculation and to gradually ramp up trading they will initially allow trading in only one financial instrument and the volume of trading will be limited to i<tex2html_verbatim_mark> contracts for i<tex2html_verbatim_mark> -th minute of market operation. Two banks had decided to cooperate with the government to kick-start the market operation. The boards of directors had agreed on trading volume for each minute of this first trading session. One bank will be buying ai<tex2html_verbatim_mark> contracts ( 1 InputThe input file contains several test cases, each of them as described below. The first line of the input contains the single integer number n<tex2html_verbatim_mark> ( 1 OutputFor 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<tex2html_verbatim_mark> numbers -- bi<tex2html_verbatim_mark> . Sample Input4 Sample OutputNo 一组数据,选择其中的一半的数变成负数,加上另一半可以和为0 |
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
long long sum;
int t;
int f[];
struct node
{
int zg;
int id;
};
node a[];
int cmp(node x,node y)
{
return x.zg>y.zg;
}
int main()
{
while(cin>>t)
{
long long sum=;
for(int i=; i<t; i++)
{
cin>>a[i].zg;
a[i].id=i;
f[i]=-;
sum+=a[i].zg;
}
if(sum%||t==) cout<<"No"<<endl;
else
{
cout<<"Yes"<<endl;
sort(a,a+t,cmp);
int s=;
for(int i=; i<t; i++)
{
if(s+a[i].zg<=sum/)
{
s+=a[i].zg;
f[a[i].id]=;
if(s==sum/)
break;
}
}
cout<<f[];
for(int i=; i<t; i++)
{
cout<<' '<<f[i];
}
cout<<endl;
}
}
return ;
}