|
|
back to boardGive me some test ! why I always get WA at test 1? #include<iostream> using namespace std; int n; long long k,res,a[21],h; void dfs(long long t,long long sum) { if(t==n){ if(sum>res) res=sum; } for(int i=t;i<n;i++) { if(sum+a[i]<=h) dfs(i+1,sum+a[i]); } } int main() { int i; long long t,sum; k=res=0; scanf("%d",&n); k=0; for(i=0;i<n;i++) { scanf("%ld",&a[i]); k+=a[i]; } h=k/2; if(n==1) cout<<a[0]<<endl; else if(n==2) { if(a[0]>a[1]) cout<<a[0]-a[1]<<endl; else cout<<a[1]-a[0]<<endl; } else if(n>=3) { t=0,sum=0; dfs(t,sum); cout<<k-2*res<<endl; } return 0; } |
|
|