SGS Programming Challenge P4 - Toy in Psychology Class

View as PDF

Submit solution

Points: 17 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

Andy is exploring how toys impact a person's happiness level in his psychology class. He recruited a study participant named Jamie.

Jamie can select N toys from the store to be his birthday gifts, and he can exchange toys with his friends. There are M types of toys.

For the ith toy (1iM), Jamie can select at most Si of it from the store, and it has a base happiness value of Hi. However, if Jamie owns multiple of the same toy, the happiness value Jamie gets from it decreases: the second toy will only give him 12 of Hi happiness, the third toy will give him 13 of Hi happiness, and the Sith toy will give him 1Si of Hi happiness. Note that if the happiness value is a decimal, it will be rounded down to the nearest integer.

Jamie has K friends. His ith friend, where 1iK, has an infinite amount of toy Bi and is willing to exchange one of his toy Bi with one of Jamie's toy Ai, but Jamie will lose Di happiness in the process. It is worth noting that Jamie can refuse an exchange or repeat an exchange as many times as he wants as long as he has the appropriate toy for exchange.

You need to find the maximum amount of happiness Jamie can achieve after some (possibly zero) exchanges.

Constraints

For all subtasks:

1N1000

1M100

0K100

0Si100

1Hi,Di106

1Ai,BiM

Subtask 1 [15%]

K=0

Subtask 2 [85%]

No additional constraints.

Input Specification

The first line contains three integers N, M, and K.

The following M lines contain two integers Hi and Si.

The following K lines contain three integers Ai, Bi, and Di.

Output Specification

Output an integer that represents the maximum sum of happiness value Jamie can achieve.

Sample Input

Copy
4 5 2
100 1
20 2
30 1
200 0
10 4
5 4 150
3 2 5

Sample Output

Copy
200

Sample Explanation

Jamie selects one of each toy 1,2,3,5 from the store and exchanges his toy 5 with his first friend's toy 4.


Comments

There are no comments at the moment.