Блог пользователя radical

Автор radical, история, 9 лет назад, По-английски

The proble is here. here I have try my best to solve it.... But my method is too complex that got TLE. My code is here.

Теги gym, ktu
  • Проголосовать: нравится
  • +6
  • Проголосовать: не нравится

»
9 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

It can be solve in O(n2) time per testcase if you something similar to two pointers instead of binary search. Let me explain:

At each position we try to increase the answer as much as possible (that is, as long as the 1 larger submatrix still has sum ≤ w). Now notice that the answer can only increase n times — so the whole thing is O(n2) (using prefix sums as you did).

Here's my AC code: link