Please read the new rule regarding the restriction on the use of AI tools. ×

kaffan_69's blog

By kaffan_69, history, 4 years ago, In English

Dedicate Length Nikhil wants to bring sofa(s) to his room. But he wants to dedicate the entire length of the room to the sofa(s) (yes I know he is a bit weird). Now Nikhil's room length is W meters, and when he went to the shop he found out sofas of two types, one of length N and other of length M. Now, let Nikhil know how many sofas of the first and second type he should buy to reduce wastage of space. First minimize the space wastage then, if similar result arises always prefer the sofa with a larger length. In case N==M give preference to second sofa.

Input format The first line contains an integer T, denoting the number of test cases. Each test case contains three integers W,N and M.

Output format For every testcase print two integers a and b, number of sofa of type 1 and 2 respectively.

Constraints: 1<=T<=10 1<=N,M,W<=10000

Example Input 1 24 3 5

Output 3 3

Explanation Nikhil will buy 3 sofas of size 3 and 3 sofa's of size 5.

  • Vote: I like it
  • -16
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Let's say our answer consists of X "N sized sofa" and Y "M sized sofa". So we have X*N + Y*M <= W. You can bruteforce the values of X and for each X, binary search the value of Y (or vice versa) and pick the answer that satisfies the other conditions.