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

why Compilation error
Posted by xxsp 27 Apr 2007 21:04
I think my code is right ,but the result is Compilation error.who can tell me the reason.
#include<iostream>
using namespace std;

int sum,average,min;

void fun(int *num,int i,int n,int current){
    if(i<n){
        fun(num,i+1,n,current);
        current+=num[i];
        int temp=sum-2*current;
        temp=(temp>0?temp:-1*temp);
        if(temp<min) min=temp;
        if(current<average)
            fun(num,i+1,n,current);
    }
}

void mySort(int *num,int n){
    for(int i=1;i<n;i++){
        int j=i-1,
            temp=num[i];
        while(j>=0&&num[j]>num[i]){
            num[j+1]=num[j];
            j--;
        }
        num[j+1]=temp;
    }
}

int main(){
    sum=0;
    int num[20];
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>num[i];
        sum+=num[i];
    }
    average=sum/2;
    min=sum;
    mySort(num,n);
    int current=0;
    fun(num,0,n,current);
    cout<<min<<endl;
    return 0;
}