Test instructions
Enter n number, number I ai satisfies 1≤ai≤i. Adds a symbol to each number, and the value is 0.
Analysis:
Starting with the largest element (assuming K), the SUM/2 can be sorted out. With the removal of the set of K, it will be possible to make up SUM/2-a[k]. As long as sum is even, there must be a solution.
Code:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace Std;
const int maxn=1e6+5;
int A[MAXN];
int R[MAXN];
BOOL CMP (int x,int y)
{
return a[x] < a[y];
}
int main ()
{
int n;
int i;
while (~SCANF ("%d", &n))
{
Long Long sum=0;
for (i=0;i<n;i++)
{
scanf ("%d", a+i);
Sum+=a[i];
R[i]=i;
}
if (sum&1)
{
cout<< "No" <<endl;
Continue
}
Sort (r,r+n,cmp);
sum>>=1;
for (i=n-1;i>=0;i--)
{
int j=r[i];
if (a[j]<=sum)
{
SUM-=A[J];
A[j]=1;
}
Else
{
A[j]=-1;
}
}
printf ("yes\n%d", a[0]);
for (i=1;i<n;i++)
printf ("%d", a[i]);
printf ("\ n");
}
return 0;
}
UVA 1614-hell on the