Submission : (https://codeforces.me/contest/1692/submission/275124032)
Problem : (https://codeforces.me/contest/1692/problem/E)
Why this approach fails, can anyone give some counter test case?
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3676 |
| 2 | Kevin114514 | 3659 |
| 3 | jiangly | 3640 |
| 4 | turmax | 3450 |
| 5 | tourist | 3408 |
| 6 | strapple | 3360 |
| 7 | Um_nik | 3354 |
| 8 | squareOf105 | 3348 |
| 9 | maroonrk | 3312 |
| 10 | idontwannadothis…e | 3191 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 155 |
| 2 | nik_exists | 151 |
| 3 | maspy | 149 |
| 4 | AmShZ | 145 |
| 5 | Um_nik | 143 |
| 6 | Errichto | 139 |
| 7 | BledDest | 136 |
| 8 | adamant | 135 |
| 9 | maroonrk | 132 |
| 10 | cry | 130 |
Submission : (https://codeforces.me/contest/1692/submission/275124032)
Problem : (https://codeforces.me/contest/1692/problem/E)
Why this approach fails, can anyone give some counter test case?
| Name |
|---|



Consider array
0 1 1 0 1 1 0, target sum is 1. Clearly it can't be done in less than 5 operations, because you must remove at least two 0s to be able to remove at least three 1s. But your approach would remove both outer zeros and setzeroto 1, then remove 3 more 1s, leading to a total cost of 4. It doesn't take into account that both outer 0s had to be removed.The correct answer is 4 your algorithm returns 3.
The reason it fails in this case is that it performs the correct steps but only counts removing zeros from both ends as 1 operation. (the last else statement in your loop)
If you correct it your approach will still be incorrect as in the case:
After the fix your algorithm will return 8, instead of the correct 5 (it remove the first 5 numbers)
As far as I know there is no greedy solution to the problem.
This problem is equivalent to finding a subarray of maximum size with a sum equal to K (the numbers you leave). This can be solved with a sliding window.
Thank you.
Yeah, i later tried sliding window and it worked, i was just curious whether it can be done with two pointers alone but it doesn't seem to work. thank you once again.