Jumpstart Interview Problem

Revision en1, by Pieck, 2021-07-21 12:34:15

Recently I encountered a problem in one of the coding rounds that I attended and as of yet I am unable to solve it, or even find a direction in which to tackle this. I've tried using greedy or dp but could not find any solution. I don't know what the difficulty of the problem might be, but I thought of sharing it anyway. Any help would be appreciated.

Problem Statement:
You are standing in an election for your college. To win the election you need to win maximum number of hostels out of N possible. Your friends come up with a strategy to help you win. According to them for a given hostel i (1<=i<=N) the campaigning in that hostel starts from day a[i]. You are given L (the end date for campaigning). To win in a particular hostel i, you can start campaigning in that hostel from a[i] onward (a[i] inclusive), but you need to campaign for at least b[i] days straight (without any breaks) to win in that hostel, such that your last campaigning day doesn't exceed L.

Constraints:
1<=T<=1000
1<=N<=1000, 1<=L<=1000
1<=a[i], b[i]<=1000

Input:
T (testcases)
N L
a[1] b[1]
a[2] b[2]
...
...
a[N] b[N]

Output:
X (Maximum hostels you could win)

Sample Testcase:
Input:
1
2 10
2 2
2 7
Output:
2
Explanation:
You campaign from day 2 to day 8 in hostel 2 and from day 9 to day 10 in hostel 1.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English Pieck 2021-07-21 14:59:19 14 Found the solution!
en1 English Pieck 2021-07-21 12:34:15 1485 Initial revision (published)