Here is the submission..... https://codeforces.me/contest/1490/submission/108030618
It works in other online editors if i copy paste the Test 1... But it gives TLE on test 1 on submission.
Here is the submission..... https://codeforces.me/contest/1490/submission/108030618
It works in other online editors if i copy paste the Test 1... But it gives TLE on test 1 on submission.
| № | Пользователь | Рейтинг |
|---|---|---|
| 1 | Kevin114514 | 3722 |
| 2 | Benq | 3676 |
| 3 | jiangly | 3640 |
| 4 | turmax | 3450 |
| 5 | tourist | 3408 |
| 6 | strapple | 3360 |
| 7 | Um_nik | 3354 |
| 8 | squareOf105 | 3348 |
| 9 | maroonrk | 3196 |
| 10 | idontwannadothis…e | 3191 |
| Страны | Города | Организации | Всё → |
| № | Пользователь | Вклад |
|---|---|---|
| 1 | maroonrk | 153 |
| 2 | Qingyu | 152 |
| 3 | nik_exists | 151 |
| 4 | AmShZ | 147 |
| 4 | maspy | 147 |
| 6 | Um_nik | 142 |
| 7 | Errichto | 139 |
| 8 | adamant | 136 |
| 9 | BledDest | 134 |
| 10 | AksLolCoding | 132 |
| Название |
|---|



Your "prev" variable is declared inside the while loop, so every time it is reinitialized with a garbage value. You can declare this variable before the while loop.
As far as I can tell, you wanted to keep the previous value of the array's element into the variable
prev. But if you take a closer look at the code, you declareprevat the same level asnow, so after you go out of the loop,prevshould be logically gone. And also you did not give any initial value toprev, there will be an undefined behavior when you are trying to use it. If you happened to have the correct answer, I think the compiler actually reuses the same memory ofprev, so that time your answer will always be correct. But sometimes the compiler will try to do different things, like assignprevwith zero, and on Codeforces it did that, I confirmed it by printingprevthen exit after your 18-th line.In conclusion, you are doing things that make undefined behavior occurs. One fix is just to move the
prevvariable to the outer scope.