F.A.Q
Hand In Hand
Online Acmers
Forum | Discuss
Statistical Charts
Problem Archiveproblemset
Realtime Judge Status
Authors Ranklist
 
AC Formular
Code Challenge
STD Contests
VIP Contests      
Virtual Contests      
C/C++/Java Exams     
DIY Contests       
Author ID 
Password 
 Register new ID

Treasure Division

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 331    Accepted Submission(s): 67


Problem Description
Ant Tony and Monkey Luffy have discovered a big treasure.It turns out to be a box of gold coins.There are N gold coins in the box.However,the gold coins are not all the same.Every gold coin has a value Vi.Now they wants to divide this big treasure into two halves.The number of gold coin differ in two half must be no more than one.Tony and Luffy wants to know the fairest division,ie,the division which minimize the difference between each parts.

 

Input
Input contains multiple cases.Test cases are separated by several blank lines.

Each test case starts with a integer N(1<=N<=30) ,indicating that there are N gold coins int the treasure box.Followed by one line contain N integer,the ith integer vi (1<=vi<=2^30),representing the value of coin i.
 

Output
For each case,output the least difference that could be found in one fairest division.
 

Sample Input
3 2 2 4 4 1 2 3 6
 

Sample Output
0 2
Hint
In sample 1,we can divide the 3 gold coins into {1,2},{3}, their difference is 0. In sample 2,we can divide the 4 gold coins into {1,4},{2,3}, their difference is 2,which is also the least difference that could be made.
 

Source
 

Recommend
gaojie
 

Statistic | Submit | Discuss | Back

Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2010 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000426(s) query 1, Server time : 2010-09-03 19:20:30, Gzip enabled