Hi , I am unable to understand why my solution gives TLE on test case 4 .
Link to my solution — https://codeforces.me/contest/1529/submission/117265714
It would helpful if someone could point out the flaw in the solution . Thanks in advance !!
| # | User | Rating |
|---|---|---|
| 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 |
| # | User | Contrib. |
|---|---|---|
| 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 |
Hi , I am unable to understand why my solution gives TLE on test case 4 .
Link to my solution — https://codeforces.me/contest/1529/submission/117265714
It would helpful if someone could point out the flaw in the solution . Thanks in advance !!
| Name |
|---|



Just add these lines in the main. ~~~~~ ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); ~~~~~
Had the same problem as you, you have to use fast input (i.e. paste this lines at the beggining of main so that the input is readed faster):
ios::sync_with_stdio(false); cin.tie(NULL);
Hey you are doing some extra work like initializing whole dp array everytime and using endl, so it's a good practice to use faster input/output i.e, ios_base::sync_with_stdio(0);cin.tie(0);, so that the code doesn't TLE, otherwise the code is fine.