Vera and Canada Day
Time limit2sMemory limit512 MB
After each laser is added, choose one of four L-shaped firing orientations per laser so that the total awe from lasers hit by beams is maximized.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Graph, Sorting, Implementation
- Solved
- No attempts yet
Problem
Vera is preparing a laser show for Canada Day. She places lasers on the xy-plane one at a time, and laser goes to . No two lasers share a position.
Every laser fires two beams in perpendicular axis-aligned directions. The four possible orientations are up and left, left and down, down and right, right and up. When a beam hits laser , the show gains awe and the beam stops there, so one beam hits at most one laser, the closest one in the direction it was fired. Beams do not interfere with each other, so they may cross and two lasers may fire at each other. A laser can be hit by several beams, and every hit adds its awe value separately.
After Vera places laser , she wants the maximum total awe value over all orientations of the lasers placed so far. Each laser is oriented independently, and the orientations may be chosen again from scratch for every answer.
Input
The first line contains the integer ().
Each of the next lines contains the integers , , (, ). The lasers are placed in the order given in the input, and for .
Output
Print lines. Line contains one integer, the maximum total awe value after lasers through have been placed.