Reseller's Eye
Time limit2sMemory limit128 MB
Given a budget and multiple sellers each offering a fixed bundle of items (buy all or none), choose a subset of sellers within budget to maximize resale profit, a bundled knapsack problem.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Greedy, Array
- Solved
- No attempts yet
Problem
Every morning, Minhyuk the reseller browses all sorts of fan-hobby sites to check the going prices of goods. While researching prices as usual, he felt the phone in his hand getting hot but paid it no mind, and before long the phone exploded!
When he came to, Minhyuk had gained a superpower: whenever he sees an item posted on the Peaceful Secondhand Land marketplace, he can tell the price at which he could resell that item tomorrow. Delighted, he named this power the Reseller's Eye.
On the marketplace's 'quitting the hobby' board, people who have given up their hobby sell their goods; they part with their beloved collectibles all at once to sever their ties. In other words, to buy from a person, you must buy all of that person's collectibles.
Now a true reseller, Minhyuk wants to buy collectibles from these people and resell them at a high price tomorrow. Buying without exceeding his capital, from which people should he buy to maximize the profit he makes tomorrow?
Input
The first line contains , the capital the reseller has today. ()
The second line contains two integers and : is the number of kinds of collectibles, and is the number of people selling goods. (, )
Each of the next lines contains two integers and : is the current price of the -th collectible and is its tomorrow price revealed by the Reseller's Eye. (; this is called the item number.)
Finally, lines describe the collectibles each person sells. Each line begins with , the number of kinds of collectibles that person has, followed by the item number and the count of each collectible that person sells. ()
Output
Print the maximum profit the reseller can make tomorrow.