Doremy's IQ
Practice this coding question on Coding Gurukul.
Problem statement
Doremy is reviewing a calendar of training contests for a learning club. Each contest is available on exactly one day, so postponing a difficult review is not possible. Her starting review capacity is q, and the club wants a schedule that completes as many reviews as possible. Your task Choose which of the n contests to review, in their given order. Before a review, the current capacity must be positive. If that contest's difficulty exceeds the current capacity, completing it reduces capacity by one; otherwise capacity stays unchanged. Skipping a day does not change capacity. Important details Print a binary schedule with 1 for a review and 0 for a skipped day. Maximize the number of reviews. Among equally good schedules, print the lexicographically smallest binary string: at the first differing day, 0 is smaller than 1. Once capacity reaches zero, no more reviews are possible, even for an easy contest. Worked example With q = 1 and difficulties 2 1 2, reviewing day 1 would exhaust capacity immediately. Skipping day 1 lets Doremy review day 2 without a loss and day 3 with a loss. Thus 011 completes two reviews and is optimal. For two difficult days and q = 1, both 10 and 01 complete one review; the required answer is 01.
Input format
First line: t. For each case, read n q, then n contest difficulties.
Output format
Print one binary string of length n per case, using the optimal schedule and tie rule above.
Constraints
1 <= t <= 100; 1 <= n <= 1000; sum of n <= 1000; 1 <= q, difficulty[i] <= 1000000000.
Sample input
1 3 1 2 1 2
Sample output
011
Sign in to run or submit a solution in C++, Java or Python.