PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#QHD0000047. Chia tiền xu công bằng (Dividing Coins)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Chia tiền xu công bằng (Dividing Coins)
Dividing Coins
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
A bag contains individual coins with values . Assign every coin to exactly one of two people; coins cannot be split. Either person may receive no coins. Your task is to minimize the absolute difference between their total values.
Input
The first line contains . If , the next line contains the coin values .
Output
Print the smallest difference between the two sums.
Subtasks
The independent scoring groups have the following complete constraints:
- Subtask 1 (20%): , .
- Subtask 2 (30%): , .
- Subtask 3 (50%): , .
Examples
Input
3
2 3 5
Output
0
Explanation
The total is . Give the coin of value to one person and coins and to the other: both receive , and the difference is .