Luigi's Calculations
InterviewTime limit1sMemory limit1024 MB
Given tire range [A, B], rim range [C, D], and divisor k, find x and y with x + y divisible by k and the largest possible sum, or report -1.
Problem
Luigi is good at choosing tires. Recently he asked Guido to run calculations that find the best combination of three factors: the road, the tires, and the rims.
In Luigi's calculations, the road is described by the number , the frequency of micro-bumps. The tires and rims are described by the numbers and , their toughness coefficients on Luigi's personal scale. Guido found through experiments that a combination is valid only if . In other words, the sum of the tire and rim coefficients must be divisible by the frequency of micro-bumps.
Luigi always works at full capacity and wants the toughest tires from his store's stock. The store sells tires with any toughness coefficient from to , and rims with any coefficient from to . If several valid options exist for a given road, Luigi picks any option whose coefficient sum is maximal.
Write a program that takes , , , , and and determines which tires and which rims Luigi should sell.
Input
The only line contains five natural numbers (), the limits of the assortment and the frequency of micro-bumps on the road.
Output
Print one line with two numbers and (, ), the answer to the problem. If no answer exists, print -1.