Cod sursa(job #482982)

Utilizator darrenRares Buhai darren Data 6 septembrie 2010 14:20:00
Problema Semne Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <ctime>
#include <cstdlib>
#include <fstream>

using namespace std;

long long n, s;
int v[50001];
bool h[50001];
long long sact;

int main()
{
	ifstream fin("semne.in");
	ofstream fout("semne.out");

	fin >> n >> s;
	for (int i = 1; i <= n; sact += v[i], ++i)
		fin >> v[i];

	srand(time(0));

	while (sact != s)
		if (sact  > s)
		{
			int aux = rand() % n + 1;
			while (h[aux])
				aux = rand() % n + 1;

			h[aux] = true;
			sact -= 2 * v[aux];
		}
		else
		{
			int aux = rand() % n + 1;
			while (!h[aux])
				aux = rand() % n + 1;

			h[aux] = false;
			sact += 2 * v[aux];
		}

	for (int i = 1; i <= n; ++i)
		fout << (h[i] == 0 ? '+' : '-');

	fin.close();
	fout.close();
}