NOI '08 P3 - Hiring Employees

View as PDF

Submit solution

Points: 25 (partial)
Time limit: 1.0s
Memory limit: 128M

Problem type
National Olympiad in Informatics, China, 2008

After the successful Olympic bid, BuBu's unremitting efforts finally landed him a position as the head of the human resources department for a subsidiary company of the Olympic committee. It's BuBu first day of work and he already encountered a challenging problem: recruit a group of short-term employees for a new Olympic project. After some estimation, it is known that this project will require N days to complete, during which, day i will require at least A_i employees.

BuBu learned that a total of M types of employees are up for hire. Type i employees will work from day S_i to day T_i, and must be paid a total of C_i dollars. A new broom sweeps clean, so to prove that he can do an astounding job, BuBu wishes to use the minimum possible cost to hire enough employees. This is really not his strength, so BuBu has found you! He hopes that you can help him design an optimal hiring scheme.

Input Specification

The first line contains two integers N and M, representing the number days required to complete the project and the number of types of employees up for hire.
The second line will contain N nonnegative integers, representing the minimum number of employees needed for each day.
For the following M lines, each line will contain three integers S_i, T_i, and C_i, describing one type of employee. Their meanings are outlined above. For the sake of simplicity, we can assume that there will be an unlimited number of employees for each type.

Output Specification

Output a single line with a single integer, the cost of the optimal hiring scheme.

Sample Input

3 3
2 3 4
1 2 2
2 3 5
3 3 2

Sample Output



Hire 3 type-1 employees and 4 type-3 employees.


For 30\% of the test cases, 1 \le N, M \le 10, and 1 \le A_i \le 10.
For 100\% of the test cases, 1 \le N \le 1\,000, and 1 \le M \le 10\,000. Also, other values in the data will not exceed 2^{31} - 1.

Problem translated to English by Alex.


There are no comments at the moment.