Recycling Pens Problem Statement

Imagine you have a certain number of empty pens, and some money in your pocket. For each pen, you can choose to either recycle it for a reward or buy a refill to make it usable again. Your goal is to find the maximum number of usable pens you can achieve given the constraints.

Example:

Input:
N = 5, R = 10, K = 2, C = 3
Output:
4
Explanation:

Recycle one pen to get 2 rupees, resulting in 12 rupees. With this, buy 4 refills and combine with 4 pens to make them usable, achieving the maximum of 4 usable pens.

Constraints:

  • 1 ≤ T ≤ 10^5
  • 1 ≤ N ≤ 10^9
  • 0 ≤ R ≤ 10^9
  • 1 ≤ K ≤ 10^9
  • 1 ≤ C ≤ 10^9
  • Time limit: 1 sec

Input:

The first line contains integer 'T', the number of test cases. Each test case consists of four space-separated integers: 'N', 'R', 'K', and 'C'.

Output:

For each test case, output the maximum number of usable pens.
Note:
No need to print anything. Just implement the solution function and return the result.
Be the first one to answer
Add answer anonymously...
Postman Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
Awards 2025
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits
Stay ahead in your career with AmbitionBox app