spoj#RPLK. Kind and gently
Kind and gently
Giselle is working on her house, as her husband won't be able to help in the task, she gently asks you for help, the task is very simple, Giselle wants to build some stairs that communicate two floors in the house, the stairs will be made of W segments of wooden, she is very confident on building the stairs, but she wants to build the stairs with some separation between steps. As you know, the end of a step is overlapped by the beginning of the other, and so on, between steps there are a single separation, as Giselle is very conservative, she wants to build the stairs using at most W segments of wood.
The next image will help you to understand the task
As you can see in the image, there is a single separation between each step relating to the height and the width of every step.
Giselle wants to build stairs using E pieces of wood that she wants to cut into at most W steps. You can only cut vertically and can't rotate the given pieces. Each step's width must be exactly M+1. M is the overlap and 1 is a constant width left placing feet.
INPUT:
The first line of the test data will start with an integer T representing the T test cases, then, T cases will follow.
Each case starts with four positive integers (E,M,K,W) denoting E pieces of wood, M meters of overlap, K height of separator between each step and W, the maximum number of steps that can be cut out. Next, E lines will follow, each with two integers Eh and Ew representing respectively the height and the width of each piece of wood Giselle has.
OUTPUT:
You must output the string “Scenario #i: “ where i is the number of test case you're analyzing (starting by 1), followed by the maximum amount of height that you can possibly build
INPUT |
OUTPUT |
3 5 1 1 3 6 2 5 10 4 20 3 15 1 1 3 1 0 5 3 15 2 20 1 60 2 1 1 25 15 10 12 10 |
Scenario #1: 19 Scenario #2: 15 Scenario #3: 145 |
Explanation of the first case:
You can only cut the segment of width 6 into one piece, but the 5 segment of width 10 you can cut it into 5 pieces, as you only need 3 pieces to use, the maximum height will be of 6+5+5+3 = 19
CONSTRAINTS:
(1 <= Width and Height of each wooden piece <= 1000) = WiHi
Small input (40%)
1<= T <=200
1<= {E,K,M} <=100
WiHi <= M <= 100
1<= W <=100
Large Input (60%)
1<= T <=10
1<= {E,K} <=100,000
WiHi <= M <= 1,000
1 <= W <= 10,000