Starry Night (Easy)
Time limit1sMemory limit512 MB
Given N stars whose brightness drops by 1 per Manhattan step, find the total brightness over all cells in a given rectangle.
- Level
Medium7 of 10
- Topics
- Prefix sum, Math, Array
- Solved
- No attempts yet
Problem
This problem and the Hard problem are the same problem with different input limits.
Star is taking photos of the night sky outside. Star wants to frame the best-looking photo and display it. While deciding how to pick the best photo, Star decides to score each photo as follows.
The sky at that time can be drawn as a 2D grid, and each cell is written as . The sky region in a photo is always a rectangle, and no photo includes only part of a grid cell.
Given stars, where star is at with brightness , the brightness at cell is computed as follows.
If the bottom-left cell of the photo's grid is and the top-right cell is , the score of the photo is computed as follows.
Given the stars and the information about the photo, compute the score of the photo.
Input
The first line contains the number of stars .
Each of the next lines contains the position and brightness of the -th star. No two stars are at the same position.
The last line contains . The bottom-left cell of the photo is , and the top-right cell is .
All input values are integers.
Output
Print the score of the photo.