Account
GitHubFeedback
Drafts and results saved on this device
Submit on CSES.fi
CSES Problemset/Introductory Problems

Apple Division

#1623
Ask AI

Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.

Open Claude Desktop

Time limit:1.00 s
Memory limit:512 MB
Unsolved
Download Tests (.zip)

There are nn apples with known weights. Your task is to divide the apples into two groups so that the difference between the weights of the groups is minimal.

Input

The first input line has an integer nn: the number of apples.

The next line has nn integers p1,p2,…,pnp_1,p_2,\dots,p_n: the weight of each apple.

Output

Print one integer: the minimum difference between the weights of the groups.

Constraints
  • 1≤n≤201 \le n \le 20
  • 1≤pi≤1091 \le p_i \le 10^9
Sample Test Cases (1)
Example 1ID: sample-1
Input
5
3 2 7 4 1
Expected Output
1
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|1 line, 0 chars
Test Bench
Download .zip
Input (stdin)
5
3 2 7 4 1
Expected Output
1