## CEOI '18 P1 - Cloud Computing

View as PDF

Points: 15 (partial)
Time limit: 1.4s
Memory limit: 256M

Problem type

Johnny is founding Bytecomp, a company that offers computing power in the cloud. Companies with this profile usually have many fast computers on which customers' computations can be made.

Johnny still has not bought any machines. He went to a computer shop and received a list of all available computers. Every computer is specified by the number of (processor) cores , the clock rate , and the price . Such a computer contains separate cores that do not interfere with each other, so they can be assigned to different tasks.

When a customer makes an order for resources, she specifies the required number of cores and the minimum needed clock rate . An order also contains the price that the customer is willing to pay in return. If an order is accepted, Bytecomp needs to provide exclusive access to computing power required by the customer. Johnny needs to choose cores (possibly from different computers), each with clock rate at least . Those cores cannot be assigned to any other order.

Help Johnny earn as much as possible: choose an optimal subset of orders to accept and a subset of computers from the shop to satisfy all the accepted orders. Your goal is to maximize the total profit, that is, the difference between earnings for providing computing power to customers and the cost of buying the computers.

#### Input

The first line of the standard input contains an integer , the number of computers that are available at the shop. Each of next lines contains a description of one computer. It consists of three space-separated integers , , and which represent the number of cores, the clock rate, and the price, respectively.

The next line contains an integer , the number of orders. Each of next lines contains a description of one order. It consists of three space-separated integers , , and which represent the number of cores needed, the minimum allowed clock rate, and the customer's budget, respectively.

#### Output

The only line of the standard output should contain one integer, the maximum total profit that can be achieved.

The test set is divided into the following subtasks with additional constraints. Tests in each of the subtasks consist of one or more separate test groups. Each test group may contain one or more test cases.

#### Sample Input 1

4
4 2200 700
2 1800 10
20 2550 9999
4 2000 750
3
1 1500 300
6 1900 1500
3 2400 4550

#### Sample Output 1

350

#### Explanation for Sample Output 1

There are four available computers and three orders. It is optimal to buy two quad-core computers that cost and ( in total) and then accept the first two orders to earn in total. We then have four cores with clock rate and four cores with clock rate . We can assign any six of them to the second order (clock rate needed) and one to the first order (clock rate needed). One core will not be used, which is allowed.

The total profit is .