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(map(int, input().split())) # Simulate the processing to get start and end times heap = [] for _ in range(k): heapq.heappush(heap, 0) starts = [] ends = [] for ai in a: start = heapq.heappop(heap) end = start + ai starts.append(start) ends.append(end) heapq.heappush(heap, end) sorted_ends = sorted(ends) count = 0 # Check each solution for being interesting for i in range(n): s_i = starts[i] a_i = a[i] found = False for q in range(1, a_i + 1): t_start = s_i + q - 1 t_end = s_i + q # Calculate m_initial and the count of completions in the interval m_initial = bisect.bisect_right(sorted_ends, t_start) left = bisect.bisect_right(sorted_ends, t_start) right = bisect.bisect_left(sorted_ends, t_end) cnt = right - left # Check each possible m in the range for m in range(m_initial, m_initial + cnt + 1): d = 100 * m / n d_rounded = int(d + 0.5) if d_rounded == q: found = True break if found: break if found: 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.