#QHD0000081. Mời bạn cùng đi xem phim (Bribing Friends)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Mời bạn cùng đi xem phim (Bribing Friends)
Bribing Friends
Source: USACO
Version: Phuoc Hung OJ Extended
Problem Statement
Bessie wants some friends to accompany her to a movie. Friend contributes popularity if persuaded. The aim is to maximize total popularity of all selected friends.
Normally, persuading friend costs moonies. However, this friend offers a discount of one mooney for exactly ice cream cones. Bessie may purchase any integer number of discounts, but cannot make the mooney payment negative. Precisely, if she buys discounts for friend , then must be an integer satisfying ; she spends cones and moonies.
Bessie has a budget of moonies and cones. Each friend can be selected at most once. The combined money and cone expenditures must not exceed the available resources.
Find the maximum popularity she can achieve. Choosing no friends is allowed and yields .
Input
The first line contains . Each of the next lines contains .
Output
Print one integer: the maximum total popularity.
Subtasks
-
Subtask 1 (20 points): ; ; .
-
Subtask 2 (30 points): ; ; .
-
Subtask 3 (50 points): ; ; .
Examples
Example 1
Input
3 10 8
5 5 4
6 7 3
10 6 3
Output
15
Explanation
Invite friend 1 for 4 moonies and 4 cones, and friend 3 for 6 moonies and no cones. Their combined popularity is .
Example 2
Input
2 0 3
7 2 2
9 1 3
Output
9
Explanation
There are no moonies. Three cones can fully discount friend 2, yielding popularity .