Vasya likes taking part in Codeforces contests. When a round is over, Vasya follows all…
- User
Vasya likes taking part in Codeforces contests. When a round is over, Vasya follows all submissions in the system testing tab.
There are n solutions, the i-th of them should be tested on a_i tests, testing one solution on one test takes 1 second. The solutions are judged in the order from 1 to n. There are k testing processes which test solutions simultaneously. Each of them can test at most one solution at a time.
At any time moment t when some testing process is not judging any solution, it takes the first solution from the queue and tests it on each test in increasing order of the test ids. Let this solution have id i, then it is being tested on the first test from time moment t till time moment t + 1, then on the second test till time moment t + 2 and so on. This solution is fully tested at time moment t + a_i, and after that the testing process immediately starts testing another solution.
Consider some time moment, let there be exactly m fully tested solutions by this moment. There is a caption "System testing: d%" on the page with solutions, where d is calculated as
Assistant
pythonimport heapq import bisect n, k = map(int, input().split()) a_list = list(map(int, input().split())) start_times = [] end_times = [] # Initialize the heap with k processes, available at time 0 heap = [0] * k heapq.heapify(heap) for a in a_list: available_time = heapq.heappop(heap) start_times.append(available_time) end_time = available_time + a end_times.append(end_time) heapq.heappush(heap, end_time) sorted_ends = sorted(end_times) count = 0 for i in range(n): a = a_list[i] is_interesting = False for q in range(1, a + 1): s = start_times[i] + q - 1 e = s + 1 m_start = bisect.bisect_right(sorted_ends, s) left = bisect.bisect_right(sorted_ends, s) right = bisect.bisect_left(sorted_ends, e) events = sorted_ends[left:right] times = [s] + events + [e] for j in range(len(times) - 1): current_m = m_start + j d = int((100 * current_m / n) + 0.5) if d == q: is_interesting = True break if is_interesting: break if is_interesting: count += 1 print(count)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.