Cod sursa(job #732759)

Utilizator vendettaSalajan Razvan vendetta Data 10 aprilie 2012 21:50:19
Problema Semne Scor 45
Compilator cpp Status done
Runda Lista lui wefgef Marime 0.74 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];
string rez;
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;
        rez.clear();
        for(int i=0; i<n; i++){
            int x = rand()%2;
            if (x == 0) s2 = s2+ (a[i]*1LL), rez+='+';
            else s2=s2-(a[i]*1LL), rez+='-';
        }
        if (s2 == s){
            g << rez << "\n";
            ok = 0;
        }
    }

}

int main(){

    citeste();
    rezolva();

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

    return 0;

}