Cod sursa(job #1779308)

Utilizator Alexa2001Alexa Tudose Alexa2001 Data 15 octombrie 2016 01:28:11
Problema Semne Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.91 kb
#include <bits/stdc++.h>

using namespace std;

const int Nmax = 50005;

char ans[Nmax];
int a[Nmax], n, i, p[Nmax], m[Nmax], P=0, M=0, x;
long long S;

int main()
{
    freopen("semne.in", "r", stdin);
    freopen("semne.out", "w", stdout);

    srand(time(0));

    scanf("%d%lld", &n, &S);
    S = -S;

    for(i=1; i<=n; ++i)
    {
        scanf("%d", &a[i]);

        if(rand()%2)
        {
            S += a[i];
            p[++P] = i;
        }
        else
        {
            S -= a[i];
            m[++M] = i;
        }
    }

    while(S)
    if(S>0)
    {
        x = rand()%P + 1;
        S -= 2*a[p[x]];
        m[++M] = p[x];
        swap(p[x], p[P--]);
    }
    else
    {
        x = rand()%M + 1;
        S += 2*a[m[x]];
        p[++P] = m[x];
        swap(m[x], m[M--]);
    }

    for(i=1; i<=P; ++i) ans[p[i]] = '+';
    for(i=1; i<=M; ++i) ans[m[i]] = '-';

    printf("%s\n", ans+1);

    return 0;
}