Roy and Flower Farm
Practice
4.2 (21 votes)
Algorithms
Approved
Dynamic programming
Easy
Open
Two dimensional
Problem
74% Success 3872 Attempts 20 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Roy is the owner of a flower plant farm and sells flower plants for a living.
Now the problem with flower plants is that they wither in a night if not taken care of. So at the end of the day, to make flower plants wither-resistant Roy uses special fertilizers.

There are N number of plants not sold on one particular day (say today), but Roy can sell them the next day (say tomorrow) if he fertilizes them tonight.
Roy sells a flower plant for Rs. X. Cost of fertilizing a plant is Rs. Y.
Currently Roy has P Rupees with him.

Given the selling price X and fertilizing cost Y of N plants, your task is to find minimum amount A (AP) that he should spend in fertilizing plants such that the total money he has after selling plants on the next day is maximized. Assume that all the fertilized plants are sold on the next day.

Input Format:
First line contains integer T - number of test cases.
Second line contains two space separated integers N and P.
Following N lines each contain two space separated integers X and Y.

Output Format:
Print the two space separated integers A and B in a new line for each test case.

Constraints:
1 ≤ T ≤ 10
1 ≤ N ≤ 100
1 ≤ X,Y ≤ 1000
1 ≤ P ≤ 10000

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
15 votes
Tags:
Dynamic ProgrammingEasyPascal's RulePascal's ruleTwo dimensional
Points:20
19 votes
Tags:
AlgorithmsApprovedDynamic ProgrammingEasyOpen
Points:20
10 votes
Tags:
AlgorithmsDynamic ProgrammingEasyTwo dimensional