Cod sursa(job #53740)

Utilizator DastasIonescu Vlad Dastas Data 23 aprilie 2007 00:18:15
Problema Semne Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.18 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]);
}

long long sum()
{
    long long sm = 0;

    for ( int i = 0; i < n; ++i )
        if ( b[a[i]] == 0 )
            sm -= a[i];
        else
            sm += a[i];

    return sm;
}

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

    // 10 20 30 40 50

    while ( sol != s )
    {
        int t = ( (rand() % n) + rand() ) % n;
        if ( b[a[t]] == 0 )
        {
            b[a[t]] = 1;
            sol = sum();
        }
        else
        {
            b[a[t]] = 0;
            sol = sum();
        }
    }

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

    fprintf(out, "\n");

	return 0;
}