Cod sursa(job #49667)

Utilizator yoyolichIoana Ardeleanu yoyolich Data 6 aprilie 2007 11:02:15
Problema Semne Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <cstdio>
#include <ctime>
#include <cstdlib>
#define maxn 50001
int x[maxn];
bool t[maxn];
int N, S;

void solve()
{
	int i, j;
	
	while(1)
	{
		for(i=1;i<=N;i++) t[i]=rand()&1;
		int sum=0;
		for(i=1;i<=N;i++) 
			if(t[i]) sum+=x[i];
				else sum-=x[i];
		if(sum==S)
		{
			for(i=1;i<=N;i++)
				if(t[i]) printf("+");
					else printf("-");
			printf("\n");
			exit(0);// ies din program
		}
	}
}


int main()
{
	time_t s;
	time(&s);
	srand(s%666013);
	freopen("semne.in", "r", stdin);
	freopen("semne.out", "w", stdout);
	scanf("%d %d\n", &N, &S);
	for(int i=1;i<=N;i++) scanf("%d ", x+i);
	solve();
	return 0;
}