# | User | Rating |
---|---|---|

1 | ecnerwala | 3648 |

2 | Benq | 3580 |

3 | orzdevinwang | 3570 |

4 | cnnfls_csy | 3569 |

5 | Geothermal | 3568 |

6 | tourist | 3565 |

7 | maroonrk | 3530 |

8 | Radewoosh | 3520 |

9 | Um_nik | 3481 |

10 | jiangly | 3467 |

# | User | Contrib. |
---|---|---|

1 | maomao90 | 174 |

2 | adamant | 164 |

2 | awoo | 164 |

4 | TheScrasse | 160 |

5 | nor | 159 |

6 | maroonrk | 156 |

7 | SecondThread | 150 |

8 | -is-this-fft- | 149 |

9 | pajenegod | 146 |

10 | BledDest | 144 |

↑

↓

Codeforces (c) Copyright 2010-2024 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Apr/15/2024 09:50:02 (l3).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

Instead of calculating min 1’s and min 2’s required for each subarray . Calculate min 1’s and 2’s required for whole array then compare the subarray sum with min sum

My submission : 248010905

There is a flaw in your logic. Consider 8 1 1 1 1 1 1 1 1, according to your logic, the corresponding array should have atleast a sum of 14 to make this one good. The correct answer is however 17.

The condition sum>=req in code is a necessary condition but not sufficient. The distribution of this sum matters consider the example 1,1,2,2 works fine with the logic but if we have 1,1,1,3 here though it has the same sum as before but the distribution of this sum is different, each of the ones must be incremented by atleast 1 so we need -3 from some element to maintain constant sum as per question but last element can't give 3 as it will become 0 after that.