Cod sursa(job #785258)

Utilizator Victor10Oltean Victor Victor10 Data 8 septembrie 2012 11:35:35
Problema Semne Scor 85
Compilator cpp Status done
Runda as1 Marime 0.87 kb
#include <cstdio>
#include <cstdlib>
#include <ctime>
#define DM 50005

int v [DM];
bool answ [DM];
char afis [] = {'-', '+'};

int main (){
	
	freopen ("semne.in", "r", stdin);
	freopen ("semne.out", "w", stdout);
	
	int n, i, pozc;
	long long S, Sc = 0;
	srand (time (NULL));
	
	scanf ("%d%lld", &n, &S);
	
	for (i = 0; i < n; ++ i) {
		scanf ("%d", &v [i]);
		Sc -= v [i];
	}
	
	while (Sc != S) {
		if (Sc > S) {
			do
				pozc = rand () % n;
			while (!answ [pozc]);
			Sc -= 2 * v [pozc];
			answ [pozc] = 0;
		}
		if (Sc < S) {
			do
				pozc = rand () % n;
			while (answ [pozc]);
			Sc += 2 * v [pozc];
			answ [pozc] = 1;
		}
		/*for (i = 0; i < n; ++ i)
			fprintf (stderr, "%c", afis [answ [i]]);
		fprintf (stderr, "Sc = %I64d\n", Sc);*/
	}
	
	for (i = 0; i < n; ++ i)
		printf ("%c", afis [answ [i]]);

	printf ("\n");
}