This greedy should not pass the judge, as it does not work for the following input:kp wrote:I solved it using both DP and greedy.

Greedy is as follows:

1. Take one guy with maximum value

2. Take two appropriate guys with minimum sum of values

However, I have not proved it.

Code: Select all

```
9
8 8 7 7 7 7 6 6 4
0
```

**8**+

**6**+

**6**and form only two teams. (The other one would be

**8**+

**7**+

**7**). However, if it started with

**8**+

**8**+

**4**, it could form three teams.