Cod sursa(job #2775381)

Utilizator betybety bety bety Data 15 septembrie 2021 16:17:42
Problema Semne Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <bits/stdc++.h>
using namespace std;
ifstream in("semne.in");
ofstream out("semne.out");
typedef long long ll;
const ll lim=5e4+5;
ll n,suma,curr;
char ch[lim];
ll v[lim];
bool tryout(ll curr,ll ind)
{
    if(curr<suma) return false;
    if(curr==suma) return true;
    for(ll i=ind;i>=1;--i)
    {
        ch[i]='-';
        if(tryout(curr-2*v[i],i-1))
            return true;
        ch[i]='+';
    }
    return false;
}
int main()
{
    ios_base::sync_with_stdio(false);
    in.tie(0),out.tie(0);
    in>>n>>suma;
    for(ll i=1;i<=n;++i)
    {
        in>>v[i];
        curr+=v[i];
        ch[i]='+';
    }
    bool ok=tryout(curr,n);
    for(ll i=1;i<=n;++i)
        out<<ch[i];
    out<<'\n';
    return 0;
}