Cod sursa(job #482981)
#include <ctime>
#include <cstdlib>
#include <fstream>
using namespace std;
int n, s;
int v[50001];
bool h[50001];
int 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();
}