Cod sursa(job #53733)

Utilizator DastasIonescu Vlad Dastas Data 22 aprilie 2007 23:38:49
Problema Semne Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.06 kb
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

FILE *in = fopen("semne.in","r"), *out = fopen("semne.out","w");

int a[50000];
int n;
long long s = 0;

int b[5000000] = {0};

void read()
{
    fscanf(in, "%d %lld", &n, &s);

    for ( int i = 0; i < n; ++i )
        fscanf(in, "%d", &a[i]);
}

int main()
{
    read();
    srand((unsigned)time(0));
    long long sol = 0;

    for ( int i = 0; i < n; ++i )
        sol -= a[i];

    // 1 2 3 4 5
    // 0 0 0 0 0
    // sol = -15

    while ( sol != s )
    {
        //for ( int i = 0; i < n; ++i )
        //{
            int t = rand() % n;
            if ( b[a[t]] == 0 )
            {
                sol += 2*a[t];
                b[a[t]] = 1;
            }
            else
            {
                sol -= 2*a[t];
                b[a[t]] = 0;
            }
        //}
    }

    for ( int i = 0; i < n; ++i )
        if ( b[a[i]] == 0 )
            fprintf(out, "-");
        else
            fprintf(out, "+");

    fprintf(out, "\n");

	return 0;
}