Chandu and his toy stack
Practice
2.8 (22 votes)
Approved
Data structures
Easy
Greedy algorithms
Open
Problem
31% Success 7384 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

After setting up the area. Chandu wanted all his toys to be stacked there in that area. So that all of them are accessible easily. Currently, He is having N stacks of toys each with height \(H_1,H_2...H_n\) (assuming all toys are of same height).Chandu did not like the configuration much and want to change the height of each stack. To increase the height of a particular stack he can add some toys to it and to decrease the height he can take out some toys from that stack. Chandu, knows that he requires X units of effort for putting up an item onto the stack and Y units of effort for removing it. Help, chandu in setting up his toys.

Input:

First Line of input contains an integer t, which is the number of test cases. then, t lines follow where first line of each test case contains three integers N, X and Y then N lines follow containing two integers each \(a[i]\) and \(b[i]\) (Initial height of \(i\;th\) stack and final height of \(i\;th\) stack.)

Output:

Output an integer which is the minimum effort required.

NOTE: he just need to make stacks of given height. Not necessarily each stack should be made from its corresponding stack.

Constraints:

\(1 \le t \le 100, \)
\(1 \le N \le 10^5, \)
\(1 \le a[i],b[i] \le 10^6\)

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
36 votes
Tags:
Greedy algorithmAlgorithmsBasics of Greedy AlgorithmsGreedy Algorithms
Points:20
30 votes
Tags:
EasyGreedy Algorithms
Points:20
42 votes
Tags:
AlgorithmsApprovedEasyGreedy AlgorithmsMathOpenSorting