NOI '08 P3 - Hiring Employees

View as PDF

Submit solution

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

Problem types
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 Ai employees.

BuBu learned that a total of M types of employees are up for hire. Type i employees will work from day Si to day Ti, and must be paid a total of Ci 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 will contain two integers N and M, representing the number of 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 Si, Ti, and Ci, 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

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

Sample Output

Copy
14

Explanation

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

Constraints

For 30% of the test cases, 1N,M10, and 1Ai10.
For 100% of the test cases, 1N1000, and 1M10000. Also, other values in the data will not exceed 2311.

Problem translated to English by Alex.


Comments

There are no comments at the moment.