#C11623. Revenue Calculation from Top M Orders

    ID: 40960 Type: Default 1000ms 256MiB

Revenue Calculation from Top M Orders

Revenue Calculation from Top M Orders

You are given a list of orders where each order is represented by three integers: customer id (c), order time (t), and order price (p). Given an integer C denoting a specific customer, two integers T1 and T2 specifying a time interval ([T_1, T_2]) (inclusive), and an integer M, your task is to calculate the total revenue generated from the top M orders (by price) made by customer C in the given time range.

In other words, first filter all orders such that c = C and T_1 \le t \le T_2. Then, sort these orders by price in descending order and sum the prices of the first M orders. If there are fewer than M orders, just sum all of them. If no orders satisfy the condition, the result is 0.

inputFormat

Input is read from standard input (stdin). The first line contains an integer N representing the number of orders. Each of the next N lines contains three space-separated integers: c, t, and p, where c is the customer id, t is the order time, and p is the price. The last line of input contains four space-separated integers: C, T1, T2, and M.

outputFormat

Output the total revenue generated from the top M orders for customer C in the time interval [T1, T2] to standard output (stdout).## sample

6
1 3 100
2 5 80
1 10 120
1 15 50
2 8 200
1 18 75
1 5 20 2
195