Cod sursa(job #732767)

Utilizator vendettaSalajan Razvan vendetta Data 10 aprilie 2012 22:06:58
Problema Semne Scor 45
Compilator cpp Status done
Runda Lista lui wefgef Marime 0.76 kb
#include <fstream>
#include <cstdlib>
#include <ctime>
#define nmax 50005

using namespace std;

ifstream f("semne.in");
ofstream g("semne.out");

int n, cnt, a[nmax];
char rez[nmax];
int viz[nmax];
long long s, s2;
void citeste(){

    f >> n >> s;
    for(int i=0; i<n; i++) f >> a[i];

}

void rezolva(){

    srand(time(NULL));

    int ok = 1;
    for(; ok; ){
        int s2 = 0LL;
        for(int i=0; i<n; i++){
            long long x = rand()%2;
            if (x % 2 == 0) s2 = s2+ (a[i]*1LL), rez[i] = '+';
            else s2=s2-(a[i]*1LL), rez[i]='-';
        }
        if (s2 == s){
            for(int i=0; i<n; i++) g << rez[i];
            ok = 0;
        }
    }

}

int main(){

    citeste();
    rezolva();

    f.close();
    g.close();

    return 0;

}