#P3755. Mobile Base Station Power Summation
Mobile Base Station Power Summation
Mobile Base Station Power Summation
Old C, a seasoned programmer, has been tasked with implementing a module for a management system of mobile base stations in the city. Each base station is considered as a point in the coordinate system with position \( (x, y) \) and an associated power attribute. Given a query rectangular region, your task is to compute the total power of all base stations that lie inside or on the boundary of the rectangle. If there are no base stations in the queried region, output \(0\).
The rectangle is defined by two opposite corners \( (x_1, y_1) \) and \( (x_2, y_2) \) (assume \( x_1 \le x_2 \) and \( y_1 \le y_2 \)). A base station at \( (x, y) \) is considered within the rectangle if:
[ x_1 \le x \le x_2 \quad \text{and} \quad y_1 \le y \le y_2 ]
inputFormat
The input begins with an integer \( n \) representing the number of base stations.
Each of the next \( n \) lines contains three integers: \( x \), \( y \), and \( p \), where \( (x, y) \) is the coordinate of a base station and \( p \) is its power.
The last line contains four integers: \( x_1, y_1, x_2, y_2 \), representing the query rectangle's lower-left and upper-right corners respectively.
outputFormat
Output a single integer: the sum of the powers of all base stations that lie inside or on the boundary of the given rectangular region. If no base station is found in the region, output \(0\).
sample
3
1 2 10
2 3 20
4 5 30
1 2 3 4
30