ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1005. Stone Pile

God Help ME !!! Why ?
Posted by Mostafa_angel 16 Oct 2008 18:43
IN which case my programe get WA ?
plz Help me...
//
//

#include <iostream>
#include <cstdlib>

using namespace std;

int main(){

    long int *w;
    int n , tmp;
    cin >> n;
    if(n>20)
        exit(0);
    w = new long int [n];
    for(int i =0 ; i < n ; i++)
        cin >>w[i];

    // bubble sort
    for(int i = 0 ; i < n-1 ; i++)
    {
        for(int j =i+1 ; j < n ; j++)
        {
            if(w[i] < w[j])
            {
                tmp = w[i];
                w[i] = w[j];
                w[j] = tmp;
            }
        }
    }

    long int minimal = w[0];
    for(int i = 1 ; i < n ; i++)
    {
        if(minimal > w[i])
            minimal-=w[i];
        else
            minimal =w[i] - minimal;
    }


    cout << endl << minimal << endl;

    return 0;
}
Re: God Help ME !!! Why ?
Posted by Slava (ssau) 11 Nov 2008 20:38
5
2
3
2
3
2

right answer is 0
Re: God Help ME !!! Why ?
Posted by JKTM 10 Apr 2017 03:09
How?
Re: God Help ME !!! Why ?
Posted by Mehedi Hasan 14 Apr 2017 03:36
3+3=6
2+2+2=6
????
Re: God Help ME !!! Why ?
Posted by 😋asmik 😜 3 Apr 2018 10:55
#include <bits/stdc++.h>
using namespace std;
bool b[18];
int n;
void get(int a,int n)
{
    for ( int i= 0; i < n; i ++)
    {
        if (a%2==0) b[i]=false;
        else b[i]=true;
        a/=2;
    }
}
int main ()
{
    int n,a[18],dn;
    __int64 s1=0,s2=0,dx,dk;
    cin >> n;
    for ( int i = 0; i < n; i++)
    {
        cin >> a[i];
        s1+=a[i];
    }
    dx=abs(s1-s2);
    dn=(1<<n);
    s1=0;
    for (int i = 1; i < dn; i++)
    {
        get(i,n);
        s1=0;s2=0;
        for (int j=0;j<n;j++)
        {
        if (b[j]) s2=s2+a[j];
        else s1=s1+a[j];
        }
        dk=abs(s1-s2);
        dx=min(dx,dk);
    }
    cout<<dx;
}