#K64177. Satisfied Clients
Satisfied Clients
Satisfied Clients
You are given a collection of candies, each with an integer sweetness level. Additionally, there are several clients, each with a request specifying a range of acceptable sweetness levels and a minimum number of candies they desire. A client is satisfied if the total number of candies with sweetness in the inclusive range \( [p_i, q_i] \) is at least \( k_i \). Your task is to determine the number of satisfied clients.
The problem can be formalized as follows: For each request \((p_i, q_i, k_i)\), let \( C = \{ c \mid c \text{ is a candy with sweetness } c \text{ and } p_i \le c \le q_i \} \). The request is satisfied if \( |C| \ge k_i \). Output the total number of satisfied requests.
inputFormat
The first line contains two integers \( N \) and \( M \), where \( N \) is the number of candies and \( M \) is the number of client requests.
The second line contains \( N \) space-separated integers representing the sweetness levels of the candies.
Each of the following \( M \) lines contains three integers \( p_i \), \( q_i \), and \( k_i \), representing a client's request for candies with sweetness in the range \( [p_i, q_i] \) and requiring at least \( k_i \) candies.
outputFormat
Output a single integer representing the number of satisfied clients.
## sample5 3
1 2 3 4 5
1 5 3
1 5 6
2 4 2
2