## NOI '08 P3 - Hiring Employees

View as PDF

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 days to complete, during which, day will require at least employees.

BuBu learned that a total of types of employees are up for hire. Type employees will work from day to day , and must be paid a total of 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 and , representing the number days required to complete the project and the number of types of employees up for hire.
The second line will contain nonnegative integers, representing the minimum number of employees needed for each day.
For the following lines, each line will contain three integers , , and , 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

14

#### Explanation

Hire type- employees and type- employees.

#### Constraints

For of the test cases, , and .
For of the test cases, , and . Also, other values in the data will not exceed .

Problem translated to English by Alex.

## Comments

There are no comments at the moment.