We can deduce that there is, since you get WA, you just need to find one.
Assuming you’ve already done the obvious and looked for any corner cases.
I haven’t solved this problem, and don’t have any test cases, so I suggest you:
- Write a simple program to create 1,000 random test cases. Keep them fairly small at first.
- Put these through your brute-force solver and direct the output to a file.
- Put these through your intended solution and direct the output to a file.
- Use your favourite comparison program to find any differences in these output files.
- Repeat until you find a test case that gives a difference.
Good luck!