It gives wrong answer ignore the last test case.
Question link -> https://www.codechef.com/problems/DIVIDE_GROUP?tab=statement
Solution link → https://www.codechef.com/viewsolution/97381828
# | User | Rating |
---|---|---|
1 | tourist | 3751 |
2 | Benq | 3727 |
3 | cnnfls_csy | 3691 |
4 | Radewoosh | 3651 |
5 | jiangly | 3632 |
6 | orzdevinwang | 3559 |
7 | -0.5 | 3545 |
8 | inaFSTream | 3478 |
9 | fantasy | 3468 |
10 | Rebelz | 3415 |
# | User | Contrib. |
---|---|---|
1 | adamant | 178 |
2 | awoo | 167 |
3 | BledDest | 165 |
4 | Um_nik | 164 |
5 | maroonrk | 163 |
6 | SecondThread | 160 |
7 | nor | 157 |
8 | -is-this-fft- | 154 |
9 | kostka | 146 |
10 | Geothermal | 143 |
It gives wrong answer ignore the last test case.
Question link -> https://www.codechef.com/problems/DIVIDE_GROUP?tab=statement
Solution link → https://www.codechef.com/viewsolution/97381828
Name |
---|
Auto comment: topic has been updated by sarvesh_bawari (previous revision, new revision, compare).
Looking at it your method seems to be taking the lowest remaining value in the array each time (call this x), then subtracting x from the k-1 highest remaining values in the array to create x groups, repeating this process until no more groups can be created. In this case the greedy method fails in the following case:
In this case 3 groups can be made from boxes [1,2,3] , [2,3,4] , and [1,4,5]. In your current solution what is happening currently is that you take the lowest value 2, and end up creating two boxes of [1,2,5], leaving only two types of candies left. Technically this can be fixed by only making one box at a time and then resorting the array after each box, but the problem constraints (1 <= A[I] <= 10^9) would cause this to TLE. In practice the actual solution doesn't require you to explicitly determine how each group is created in the solution.
Thank you........Sir.