hello_its_me's blog

By hello_its_me, 12 months ago, In English

Fortunately I was able to solve all the problems of CSES sliding window section except two. One of them is this : sliding window advertisement.

I ran out of ideas to solve this. Any one who knows how to solve it please share your idea with me. Help me out. Do you think it can be solved if i have solved the other problems ? or do i need something different for this ? Thanks in advance.

  • Vote: I like it
  • -3
  • Vote: I do not like it

| Write comment?
»
11 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

hello

»
11 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Solve the easier version (Advertisement) first. You can see that the solution looks something like this: For each fence i, try to expand as much as possible to the left and to the right until you encounter a shorter fence. Then, we will have n rectangles, and our job is just get the rectangle with the largest area.

The same concept applies to the sliding window version, where you will find the rectangle with the largest area in the sliding window. This can be handled easily using convex hull trick.