Cod sursa(job #482984)
#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");
srand(time(0));
fin >> n >> s;
for (int i = 1; i <= n; ++i)
{
fin >> v[i];
int aux = rand() % 2;
h[i] = aux;
sact += (aux == 0 ? v[i] : -v[i]);
}
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();
}