Editorial for Украса на кея


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.

Submitting an official solution before solving the problem yourself is a bannable offence.
by: maya

Тестовете можете да видите тук.

Примерно решение на C++:

#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main()
{
    int n,b[30],i,x,s1,s2,s,minr,r;
    cin>>n;
    s=0;
    for(i=0;i<n;i++)
    {
        cin>>b[i];s+=b[i];
    }
    minr=s;
    for(x=0;x<(1<<n);x++)
    {
        s1=0;
           for(i=0;i<=n;i++)
             if(x&(1<<i))s1+=b[i];
        s2=s-s1;
        r=abs(s1-s2);
        if(r<minr)minr=r;
    }
    cout<<minr<<endl;
    return 0;
}

Comments

There are no comments at the moment.