We need to understand the problem: There are n solutions, each with a_i tests. They are judged in order by k identical testing processes. At any time, a free process takes the next solution in order (based on the queue; initially queue is [1,2,...,n]) and starts testing it from test 1 to test a_i continuously. So each solution i is assigned a start time S_i when it begins testing, and it occupies a process for a_i seconds, finishing at time S_i + a_i. Since processes are used in order, the start times can be determined: It's like a k-server queue processing jobs with given durations. The order is fixed. So we can compute the start times S_i: When a process becomes free, it takes the next job. This is essentially a simulation: We maintain the earliest available time of each process (initially 0 for all). For i from 1 to n, we assign job i to the process with the earliest available time (since any free process would take it; but if multiple free at same time, they can be assigned arbitrarily, but the order of taking matters? Actually, if multiple are free at same time, they could both take the first and second? But we have a queue: at time t, if there are multiple free processes, they all will take jobs from the queue simultaneously. However, the rule: "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." So if multiple processes become free at the same time t, they will all look at the queue at that moment. The queue has some pending solutions. At that moment, each free process will take the first solution, but they can't take the same solution. Usually, the model is: Whenever a process becomes idle and the queue is non-empty, it immediately starts the next job. If multiple become idle at the same time, they will all simultaneously try to take the first job, but they cannot take the same job; but the order they take may be arbitrary but effectively we can think that they are processed in some order: the first idle process gets the first job, then the second idle gets the next, etc. But since they start at exactly the same time, the assignment may affect the start times of later jobs. However, the problem statement says: "Please note that in case when multiple processes attempt to take the first submission from the queue at the same moment (for instance, at the initial moment), the order they take the solutions does not matter." That suggests that the final outcome (the set of interesting solutions) is independent of that ordering. So we can adopt a consistent assignment rule, such as assign to the lowest-index process, or using a priority queue of processes by their available time, and when multiple have same time, assign in any order; we can simulate with a min-heap of processes times; for each job i, we pop the process with smallest available time; if there are multiple with same smallest time, it doesn't matter. Then we set S_i = that available time; then we push back time = S_i + a_i for that process. This yields a deterministic schedule that should be valid and representative for the property.
Now, we need to find for each solution i, whether there exists a test number q (1 ≤ q ≤ a_i) and a time moment t (real number) such that at that moment, solution i is being tested on test q, and the caption displays "System testing: q%", where the caption is computed based on the number of fully tested solutions by that moment, m, and d = round(100 * m / n) = nearest integer to 100m/n. So we need: round(100 * m(t) / n) = q, where m(t) is number of solutions that have been completely finished (fully tested) at time t. And at that same moment, solution i is being processed on test q, meaning that the process is currently executing test q of that solution. Note that tests are done sequentially from 1 to a_i. The test q takes the time interval (S_i + (q-1), S_i + q) (the test runs from time S_i + (q-1) to S_i + q; at the start of that interval it begins test q; at the end it completes test q. The problem says "being tested on some test q" at a time moment (possibly non-integer). So any time in that open interval (or maybe inclusive at boundaries?) Typically, at exact integer times? At time S_i + q, test q finishes and solution moves to test q+1 (or finishes if q=a_i). At time exactly S_i + (q-1) it starts test q. So at those exact endpoints, it might be ambiguous, but we can consider non-integer times anyway, so we can pick a moment in the interior. So we need existence of a real t such that t ∈ (S_i + q - 1, S_i + q) (or maybe [S_i+q-1, S_i+q) but not including completion of last test) and round(100m(t)/n) = q.
Note: When solution i is being tested on test q, it is not yet fully tested. So m(t) does not include solution i unless it has completed. So m(t) counts only those solutions j such that S_j + a_j ≤ t.
Thus, we need to find for each i, if there exists q (1 ≤ q ≤ a_i) such that the equation holds at some time within the interval.
Now, m(t) is piecewise constant between events when solutions finish. It increases by 1 at each completion time (S_j + a_j). Therefore, for a given interval (S_i+q-1, S_i+q), m(t) is constant unless some other solution finishes within that interval. Actually, m(t) can change at discrete times (completion times). Since t is continuous, within an open interval that doesn't contain any completion time, m(t) is constant. If a completion occurs exactly at an endpoint, we may need to consider interior. So for each test q of solution i, we can determine the set of times t where solution i is on test q: interval I = (S_i + q - 1, S_i + q). Within this interval, m(t) is constant except possibly at the moment when another solution finishes exactly at some point inside the interval. Since completion times are discrete (they occur at specific times), the interval can be partitioned into subintervals where m(t) is constant. For each such subinterval, we have a specific integer m. The caption d = round(100 * m / n) is computed based on m. So we need whether for any subinterval, the computed d equals q.
Thus, we can for each solution i and each test q, check if there exists a time t in I such that round(100 * m(t) / n) = q.
Alternatively, we could think: For a given solution i, we need to know during its testing interval (S_i, S_i + a_i), at each moment, what m(t) is. Since m(t) increases stepwise, we can consider the times when m(t) changes. The condition round(100*m/n) = q implies that the percentage is exactly q percent (integer). So essentially we need that during the time when solution i is on test q, the completed count m makes the rounded percentage equal to q.
Observation: The rounded percentage is an integer between 0 and 100 inclusive. But q is between 1 and a_i (a_i can be up to 150, but q may exceed 100? Actually percentage is capped at 100, but q can be greater than 100? Since a_i up to 150, q can be >100, but the caption can only show up to 100% (when m=n). So for q >100, it's impossible because round(100*m/n) is at most 100. So only tests q ≤ 100 can be interesting. But also note: if q > 100, the condition can't be satisfied because the caption can't be >100. So we can ignore tests q > 100.
Now we need to compute the schedule and then evaluate for each solution.
Constraints: n up to 1000, k up to 100, a_i up to 150. So straightforward simulation O(n log k) is fine. Then for each solution, we may need to consider up to min(a_i, 100) tests, each test we need to know m(t) during that interval. m(t) changes at most n times. So worst-case O(n * a_i * n) = 10001001000 = 10^8, maybe borderline but possibly okay in C++? But we can optimize.
Better approach: For each solution i, we know its start time S_i and finish time F_i = S_i + a_i. During its execution, other completions occur at times. For each test q (1..a_i), the interval for test q is [L = S_i+q-1, R = S_i+q). We need to know m(t) for t in (L,R). m(t) is the number of completions with F_j ≤ t. So m(t) = count of j such that F_j ≤ t. Since F_j are known. So for a given t, m(t) is simply count of F_j ≤ t. So for interval (L,R), m(t) is constant if no F_j lies in (L,R]. Actually, if any F_j equals exactly L? Since m(t) includes completions at time ≤ t. At t > L, if F_j = L, then for t > L, it's included. At t exactly L, might be ambiguous but we can take interior > L. So for t in (L,R), if there is no F_j in (L,R) and also possibly at L? For t > L, any F_j = L is counted because L < t? Actually if F_j = L, then for any t > L, we have F_j ≤ t. So m(t) will include that completion for all t > L. So the value of m(t) for t just after L is m(L+) = count of F_j ≤ L. At exactly L, it could be either including that if we consider closed? But we can choose t > L, so it's fine. So the value m(t) in (L,R) equals the count of F_j ≤ L (since any F_j = L is ≤ L, thus included) plus any F_j that lie strictly between L and R? Actually if F_j is in (L,R), then for t just above that F_j, it will be included; but the interval (L,R) is continuous, so m(t) can jump at those points. So we need to consider subintervals between successive completions. But the condition round(100m/n) = q may hold on either side of a jump. So we need to see if there exists some t in (L,R) such that m(t) equals some integer m where round(100m/n)=q. That's equivalent to: there exists some integer m such that round(100*m/n)=q and there exists t in (L,R) with m(t)=m. Since m(t) is non-decreasing, it takes a set of integer values over the interval. Specifically, let m_start = number of completions with F_j ≤ L (i.e., count of F_j ≤ L). Let m_end = number with F_j < R (since for t just before R, t<R, completions with F_j = R are not included because t<R, so not yet; but completions with F_j = R exactly are not counted until t >= R; but since interval is open at R, t<R, so not included). Actually we need to be careful: For t in (L,R), m(t) = count of F_j ≤ t. So for t approaching R from below, any completion exactly at R is not counted because t < R. So m_end (just before R) is count of F_j < R. So m(t) can take values from m_start (immediately after L) up to m_end, but only at discrete times when a completion occurs inside (L,R), the value jumps. So the set of m values attained in (L,R) is: {m_start} ∪ {m such that there exists some completion at time T in (L,R) and for t just after T, m(t) increases to m+1}. Actually if completions occur at times T1 < T2 < ... within (L,R), then for t in (L, T1), m(t) = m_start; for t in (T1, T2), m(t) = m_start+1; etc; for t in (T_last, R), m(t) = m_start + c, where c is number of completions in (L,R). So the set of values is m_start, m_start+1, ..., m_start + c, where c = number of F_j in (L,R) (not counting those at endpoints exactly L? Actually completions at exactly L are included in m_start already; completions at exactly R are not included because t<R; so they are not counted). So m(t) in (L,R) takes all integer values from m_start to m_start + c, but perhaps not all intermediate? Actually if there are multiple completions at exactly same time? Could be possible? Two solutions could finish at the same time if they started at same time and have same a_i? Or more generally, if S_j + a_j = S_l + a_l. That's possible. In that case, multiple completions occur at the same time. Then m(t) jumps by that many at that instant. But for t just after that instant, m(t) = m_start + number of completions that occurred at times ≤ that time. Since the completions are simultaneous, the set of values might skip some numbers if we consider "just after" includes all of them. Actually if two completions happen at same time T, then for t < T, m = m_before; for t > T, m = m_before+2. The intermediate m_before+1 never occurs because both finish at the same moment, so no time where exactly one is completed and the other not? However, could there be a moment exactly at T? At exact T, the definition of "fully tested by this moment"? The caption is defined at some time moment (possibly non-integer). At exact integer times, the processes finish a test exactly at that moment, and then they might start next solution. The problem says "Consider some time moment, let there be exactly m fully tested solutions by this moment". Typically, at the exact moment when a solution finishes, it is considered fully tested? Usually, if a solution finishes at time t, then at time t it is fully tested. But what about the caption at that exact moment? The problem statement: "Consider some time moment, let there be exactly m fully tested solutions by this moment." That suggests m includes those that have been fully tested up to that moment, inclusive. However, it's ambiguous whether at the exact completion time, the solution is considered fully tested. In typical continuous time modeling, we can treat m(t) as right-continuous? Or maybe it's left-continuous? But they say "by this moment", which typically includes solutions completed exactly at that moment. Since time moment can be non-integer, they likely consider that at the exact moment when a test finishes, the solution is considered fully tested (since the test ends at that moment). But the interesting condition involves a solution being tested on a test at a moment. At the same moment, if a solution finishes a test, it's ambiguous. The problem statement says "there is a time moment (possibly, non-integer) when the solution is being tested on some test q". If at the exact moment of finishing test q, it is no longer being tested on test q; it just finished. So typically we consider open intervals for the test. So for the existence, we can pick a moment strictly between start and end of test. So we can ignore exact endpoints. So for m(t) we can consider t not equal to any completion time. So we can assume m(t) is constant on intervals between completions.
Thus, for an interval (L,R) that does not contain any completion times in its interior, m(t) is constant (say m_start). If there are completions inside, the interval is broken into subintervals with different m values. However, we can treat the condition as: Does there exist any m such that round(100*m/n)=q and m is between m_start and m_start + c (inclusive of possibly m_start and m_start+c) AND there exists a subinterval of (L,R) where m(t)=m. For that, we need that m is actually attained for a positive-length interval, not just at a point. Because at the exact completion time, the value of m jumps, but at that exact moment we could choose a time exactly at that instant? But the instant is of measure zero; but the condition requires existence of a time moment (any real number) at which both conditions hold. It could be exactly at the moment when m(t) changes? At that exact moment, what is m? Typically, at the instant of completion, the solution becomes fully tested. If we consider that moment, the solution being tested? If the completion of another solution occurs at time T, then at time T, that other solution is just finished. At that same time, the current solution i might be in the middle of test q. The caption would reflect the updated m if we include that completed solution. At time exactly T, is the solution considered fully tested? The problem says "by this moment", so probably yes. But the time moment could be exactly T. However, does the condition require that at that moment the solution i is being tested on test q? Yes. So if we pick t = T, we must ensure that at t, solution i is being tested on test q. But if T is exactly the start or end of the test interval? Typically, at t = S_i + q - 1, test q begins. At t = S_i + q, test q ends. At t = S_i + q, solution i might finish test q; if q = a_i, it finishes the solution. But we consider test q; at the exact end of test q, is the solution "being tested on test q"? Probably not, it's just finishing; but the problem says "when the solution is being tested on some test q". I'd interpret that as during the execution of that test, i.e., when the process is occupied with that specific test, which is the interval (S_i+q-1, S_i+q). At the endpoints, it's transitioning, so not considered being tested on that test. So we should only consider interior points. Thus we need an interval of positive length where both hold. However, if m(t) jumps at a time that lies strictly within (L,R), then for any ε>0 small, on (T-ε, T) m(t) = m, on (T, T+ε) m(t) = m+1. At exactly T, it's ambiguous but we can avoid it. So as long as there is some interval where m(t) equals a specific value, we can pick a point inside that interval. So we need m to be equal to some value that occurs over a subinterval (open interval). That happens for values m_start, m_start+1, ..., m_start+c, but careful: if multiple completions occur at the same time T, then for t just after T, m(t) jumps from m_before to m_before+ (number of completions at T). The intermediate values (like m_before+1) may not be attained over an interval; they might be only at the exact moment if we consider left/right limits, but no interval. So to have a non-zero length interval, we need that between completions there is a gap. Since completions happen at distinct times (but they could coincide). If completions occur at distinct times, then each integer between m_start and m_start+c is attained over some interval: For example, m_start is attained from L to first completion; m_start+1 from first completion to second, etc. So all integers in that range appear. If some completions are simultaneous, then the jump may skip some integers; those skipped integers are not attained over any interval (only maybe at exact moment, not valid). So we need to consider the set of m values that occur over intervals of positive length within (L,R). That's essentially the set: all integers m such that there exists an open interval within (L,R) where m(t) = m. That is exactly the values that are taken at some time interval between completions. That is: let times be the sorted list of distinct completion times that lie in (L,R). For each gap between successive distinct times (including from L to first, and from last to R), m(t) is constant. So the set is: m(t) for t in (L, T1) = count of completions ≤ L (i.e., m_start); then after each distinct completion time, m(t) increases by the number of completions that occurred at that time. So the values are m_start, m_start + d1, m_start + d1 + d2, ..., where d_i are the counts of completions at each distinct time. So not necessarily all consecutive integers.
Therefore, we need to compute for each solution i and each test q, the set of m values that occur during the interval (L,R) as described, and check if any of those m satisfy round(100*m/n) = q.
But we can approach more systematically: Since n ≤ 1000, we can simply simulate time and events. Another approach: For each solution i, we can examine all completion events (finish times of other solutions) that fall within its testing interval, and then for each subinterval between these events, check if the rounded percentage equals the test number of the portion of the solution being executed at that subinterval.
However, we need to know for each subinterval, which test number is being executed. For solution i, its test number at time t is floor(t - S_i) + 1, as long as t ∈ (S_i, S_i + a_i) and not exactly at boundaries? Actually for t in (S_i + q - 1, S_i + q), test number = q. So given a time interval (t1, t2) within the execution of i, the test number might be constant if the interval doesn't cross a test boundary. Since test boundaries occur at S_i + integers. So we can break the execution of i into its a_i test intervals: (S_i, S_i+1) for test1, (S_i+1, S_i+2) for test2, ..., (S_i+a_i-1, S_i+a_i) for test a_i. For each of these intervals, we can see if there exists a sub-subinterval where the rounded percentage equals the test number.
Given that intervals are short (each exactly length 1), and there could be many completion events. But we can handle per solution: we have the finish times F_j for all j (j != i perhaps including i? But i finishes at S_i+a_i, which is after its tests; the interval of test q ends at S_i+q, which is before its finish time unless q=a_i. For q=a_i, the interval is (S_i+a_i-1, S_i+a_i). At time S_i+a_i, it finishes. So not included. So finish times of other solutions might lie inside these test intervals.
We can precompute all finish times F_j for j=1..n.
Then for each i and each q (1..a_i, q<=100), compute L = S_i + q - 1, R = S_i + q.
We need the set of m values that occur for t ∈ (L,R). To do that, we can compute:
m_left = number of F_j ≤ L (including any at exactly L? Since t> L, completions at L are counted). So effectively m_start = count(F_j ≤ L).
Then we need the number of distinct completion events in (L,R) and their multiplicities. Specifically, let completions in (L,R) be the set of distinct times T where some F_j equals T, with T in (L,R). For each such T, at time just after T, m increases by the count of jobs finishing at T. So the possible constant m values over intervals within (L,R) are:
- For the first subinterval: m = m_start (from L+ε to first T)
- After the first batch of completions at time T1: m = m_start + cnt(T1) (from T1+ε to next T)
- After second batch: m = m_start + cnt(T1)+cnt(T2), etc.
- Finally, after the last batch before R: m = m_start + total completions in (L,R) (from last T+ε to R-ε)
Also, if there are no completions in (L,R), then m is constant = m_start throughout.
Thus we need to check if any of these m values satisfy round(100*m/n)=q.
But careful: Is it possible that the rounded percentage equals q for a value of m that is not attained over an interval but only at a single point? For example, if at the exact moment of a completion, the m jumps, and at that exact moment, the rounded percentage might equal q. However, at that exact moment, is the solution i being tested on test q? If the completion time T equals, say, exactly L? Then at times just after L, m includes that completion. But the interval (L,R) excludes L. So if T = L, the completion is counted in m_start (since we count ≤ L). So it's fine. If T = R, then it's not counted in (L,R) because t < R. So if T = R exactly, the completion doesn't affect m in (L,R). However, consider T inside (L,R). At time exactly T, the solution is being tested? The moment T could be chosen, but the solution being tested condition: we need t such that solution i is in test q. For t = T, if T is strictly between L and R, then solution i is indeed being tested on test q (since test q runs from L to R, open endpoints). At the exact time T, is the process still executing test q? Typically, at time T, the process is exactly at the end of a test if T is integer? Actually test boundaries happen at integer times relative to S_i. Since S_i could be non-integer? S_i can be any real number, because start times are determined by previous completions. However, note that all durations are integers. Start times could be sums of integers? Initially all processes start at time 0, and each job takes integer time, so the start times S_i are integers? Let's see: All a_i are integers. The process times: Initially, all processes are free at time 0 (integer). When we assign job i to process with earliest available time, that time could be integer because all a_i are integers. Indeed, the earliest available times are always integers because they start at 0 and adding integer durations yields integers. However, if multiple processes become free at the same time, they assign jobs immediately; all times are integers. So S_i are integers, and all finish times F_i = S_i + a_i are integers. Therefore, test boundaries are at integer times: L = S_i+q-1 (integer), R = S_i+q (integer). So the interval (L,R) is an open interval between two consecutive integers. Inside that interval, t is non-integer. The completions of other jobs occur at integer times (F_j). So those completion times are integers. So they never fall inside the open interval (L,R) because L and R are integers, and (L,R) contains no integers (except possibly if L and R are not integers, but they are integers). Therefore, for any test interval (L,R) where L,R are integers, the interior (L,R) contains no integer times, and since all completion times are integers, no completion occurs strictly inside (L,R). The only possible completions that could affect m(t) for t in (L,R) are those at times ≤ L, which are counted in m_start, and those at times ≥ R, which are not counted because t<R. However, there is a nuance: what about a completion exactly at time L? That's an integer; L is integer. For t in (L,R), t > L, so if a completion occurs at exactly L, then for any t>L, that completion is counted. So it's included in m_start (since we count F_j ≤ L). Similarly, a completion at exactly R is not included because t<R. So indeed, in the open interval (L,R), m(t) is constant! Because no completion events occur inside (since they are all integers, and the interval is open and doesn't include integers). Wait, is it possible for a completion to occur at a non-integer time? Since all start times are integers and durations are integers, finish times are integers. Yes, because S_i are integers. However, what about the scenario where multiple processes become free at the same integer time and they take jobs, but those jobs start at that same integer time. So S_i are integers. So all events occur at integer times. Therefore, for any test interval (S_i+q-1, S_i+q), which is an open interval between two integers, there are no completion events inside. So m(t) is constant throughout that interval.
That simplifies everything! Indeed, because all a_i are integers, start times are integers (if we simulate as described). Let's verify: At time 0, all processes free, they start jobs at time 0. So S_1..S_k = 0. Then after a_i seconds (integer), they finish at integer times. When a process finishes at integer time T, it may take the next job immediately at time T (since queue is processed). So that job starts at integer T. So by induction, all start times are integers. So indeed, all start and finish times are integers.
Thus for each test interval (L,R) = (S_i+q-1, S_i+q), m(t) is constant (since t is strictly between two integers, and all completions happen at integer times). The value is: m(t) = number of solutions j such that F_j ≤ L (since for t just above L, any completion at L is counted, and no completions between L and R). Actually for any t in (L,R), t > L and t < R, so completions with F_j ≤ t are those with F_j ≤ L (since no F_j in (L,R) because they are integers). But what about a completion exactly at time L? If F_j = L, then F_j ≤ t holds because t > L? Actually if t > L, then F_j = L ≤ t, so yes. So m(t) = count(F_j ≤ L). However, we need to be careful: Could there be a completion at time exactly L that belongs to solution i itself? Solution i's own finish time is S_i + a_i, which is > S_i+q (since q ≤ a_i, and if q = a_i, R = S_i+a_i; but the interval is (S_i+a_i-1, S_i+a_i). The completion of i is at S_i+a_i, which is R, not L. So i's own finish not in (L,R). So safe.
Thus, m(t) is constant throughout test interval and equal to m_q(i) = number of solutions finished by time L = S_i + q - 1 (i.e., with finish time ≤ S_i+q-1). Let's denote T = S_i + q - 1. Then condition for solution i being interesting with test q is: round(100 * m / n) = q, where m = count_{j} (F_j ≤ T). Since m is integer, round(100m/n) = floor(100m/n + 0.5). So we need to check if q equals that.
But wait: The condition also requires that the solution is being tested on test q at that moment. Since m is constant over the interval, if it holds at any point, it's satisfied. So for each solution i and each test q (1 ≤ q ≤ a_i, and q ≤ 100 because round(100*m/n) ≤ 100), we can simply check whether q = round(100 * m / n) where m = number of solutions completed by time S_i+q-1.
However, we must also consider that the caption updates only when m changes, which occurs at integer times. Since m is constant over the open interval, the caption displays a constant value (the nearest integer to 100*m/n). So the condition reduces to that.
But is there any possibility that the test interval might not be fully inside the execution? For test q, the interval is (S_i+q-1, S_i+q). At the very start of solution i, S_i is integer, test 1 interval (S_i, S_i+1). For t in (S_i, S_i+1), solution i is being tested on test 1. At time exactly S_i, maybe the process just started test 1; but open interval excludes S_i, so interior is fine.
Thus, the problem becomes: For each solution i, and for each q from 1 to a_i (q ≤ 100), compute m = number of solutions j such that F_j ≤ S_i+q-1. If round(100*m/n) == q, then i is interesting. If at least one such q exists, count i.
But careful: Could there be a case where the test q is such that S_i+q-1 is exactly the finish time of some solution(s)? As argued, m(t) includes those finishes because we consider ≤ L. So that's fine.
Now, we must ensure that the computation of S_i and F_j is correct with respect to the scheduling rule. Since all times are integers, we can compute start times via a priority queue as described. However, we must confirm that the integer property holds given the note about multiple processes taking jobs simultaneously. In the simulation, when a process becomes free at time t (integer), if there are multiple free at same time, they will all take jobs from the queue at that same moment. But if we assign jobs one by one, the start time of each job taken at that moment is t. Because they all start at time t. This is consistent: all processes that become idle at the same time can start new jobs at that same time. So S_i for those jobs are t. So they are integers.
But we have to be careful about the order: if at time t, more than one process becomes free, they will all take jobs from the queue. The order of assignment may affect which job gets assigned to which process, but all start at time t. However, the assignment order could affect future start times because the durations differ. For example, suppose at time 0, two processes start jobs 1 and 2. Then at time a1 and a2, they finish. If a1 < a2, then at time a1, process 1 becomes free and takes job 3. If a2 > a1, then the start time of job 3 is a1. If we swapped which process gets which job initially (i.e., job 1 with a1 given to process A, job 2 with a2 to process B), it might affect later start times? Actually if processes are identical, the assignment of jobs to processes at simultaneous idle times does not affect the set of start times? In a multi-server queue with FIFO queue, when multiple servers become idle at the same time, they all take the next jobs from the queue. The order among them doesn't matter because they are identical and all start at the same time. However, the assignment could affect which server finishes when later? Because the jobs have different durations. If two servers become idle at the same time and there are two jobs waiting, whichever job is assigned to which server will affect the future times when those servers become idle. But does that affect the start times of later jobs? Possibly yes, because the finish times of those jobs determine when servers become available. However, the overall schedule might not be unique; but the problem says that in case of multiple processes attempting to take the first submission at the same moment, the order does not matter (i.e., the answer is independent of that ordering). So any valid schedule that respects the rule (free processes immediately take the next job from the queue, and if multiple free at same time, they all take jobs in some order) should yield the same set of interesting solutions. So we can choose any simulation method that respects the rule. The standard method using a priority queue (min-heap) of process available times, and for each job assign to the process with smallest available time (and if ties, any order) will produce a valid schedule. But we need to ensure that this schedule is indeed one that could occur under the rule. The rule: at any time moment t when a process is idle, it immediately takes the first solution from the queue. This implies that when multiple processes become idle at the same time, they all look at the queue at that moment. The queue is processed in order: each idle process takes the next solution. But the order among the idle processes doesn't matter because they all take distinct jobs; however, which idle process takes which job could affect which job gets which process, but all jobs taken at that moment start at the same time t. So the start times for those jobs are all t. Their finish times will be t + a_i. This is consistent regardless of assignment to specific processors. The order of taking jobs from the queue: suppose at time t, there are p idle processes and at least p jobs waiting. Then the first p jobs in the queue will be started at time t, each on a distinct process. The assignment of which job goes to which process doesn't affect start times because they all start at t. But it might affect which process finishes when later, but that only matters for subsequent jobs. However, the subsequent jobs are taken from the queue after these p jobs are removed. The next jobs will start when a process becomes free. The times when processes become free depend on which job they got. So the assignment could affect the sequence of finish times and thus the start times of later jobs. Is the schedule of start times uniquely determined? In a multi-server FIFO queue with identical servers, the start times are uniquely determined regardless of assignment? I think yes, for a FIFO queue, if servers are identical, the start times of jobs are the same under any assignment that respects that the next job starts as soon as any server becomes free, and jobs are processed in order. However, there is subtlety: consider two servers, jobs: a1=1, a2=100, a3=1. At time 0, both servers free, they take jobs 1 and 2. If job1 goes to server A and job2 to server B, then at time 1, server A finishes and takes job3 (starting at time 1). If instead job1 to server B and job2 to server A, then at time 1, server A (with job2) is still busy, server B finishes job1 and takes job3 at time 1. So job3 starts at time 1 regardless. So start times are the same. In general, with identical servers and FIFO, the start times are determined by the order of jobs and the availability times of servers. The assignment can affect which server gets which job, but the earliest available time for the next job after processing previous ones is the minimum finish time among the servers. Since we always assign the next job to the earliest available server, the start time of each job is the time when some server becomes free. That time is essentially the k-th smallest completion time among previous jobs? Actually there's a known result: For k identical machines processing jobs in order (online), the schedule produced by always assigning the next job to the machine with the smallest current load is optimal (makespan) but also yields a specific start time. However, if multiple machines become free simultaneously, which one gets which job might affect the future "earliest free time" ordering, but the start times of subsequent jobs are determined by the set of finish times of the currently running jobs, not by which machine has which. Since the machines are identical, the set of finish times after processing the first p jobs is the same regardless of assignment? Not exactly: The set of finish times after assigning jobs 1..p to p servers is the multiset of a_1, a_2, ..., a_p (since all start at 0). If we assign them arbitrarily, the set of finish times is {a_i} (as a multiset). So it's the same multiset. So the times when servers become free are the same set of values. Then for job p+1, its start time is the minimum of those finish times. That minimum is the same regardless of assignment. After assigning job p+1 to the server that just finished, that server's new finish time becomes start + a_{p+1} = min_finish + a_{p+1}. So the multiset of finish times changes accordingly. However, if there are multiple servers with the same minimum finish time, which one we choose could affect the multiset of finish times after assignment? Suppose we have two servers with finish times f1 and f2, both equal (say both equal to t). We assign job to one of them; after assignment, that server's new finish time becomes t + a_{p+1}, the other remains t. The resulting multiset is {t + a_{p+1}, t}. If we had assigned to the other, it's the same multiset. So the multiset is invariant regardless of which server among those with equal current finish time gets the job. So the set of finish times after each assignment is uniquely determined (as a multiset) independent of assignment decisions. Since start times of jobs are the minimum finish time among servers at that moment, and that minimum is determined by the multiset, start times are uniquely determined. So the schedule of start times (and thus finish times) is unique. So we can compute S_i using a min-heap that always picks the smallest available time; in case of ties, it doesn't matter. So we can proceed.
Thus algorithm:
- Read n, k, a[1..n].
- Simulate to compute start times S_i and finish times F_i = S_i + a_i.
Use a priority queue (min-heap) of available times, initially k zeros.
For i from 1 to n:
t = pop min from heap (earliest available time)
S_i = t
push t + a_i back into heap.
This yields S_i.
All S_i and F_i are integers.
Then, we need for each solution i and each test q (1..min(a_i,100)) compute m = number of solutions j (including possibly i? i hasn't finished yet at time S_i+q-1 unless q-1 >= a_i? But q ≤ a_i, and S_i+q-1 < S_i+a_i because q-1 < a_i (since q ≤ a_i, q-1 ≤ a_i-1). So F_i = S_i+a_i > S_i+q-1, so i not finished). So m = count_{j} (F_j ≤ S_i+q-1). So we need to count how many finish times are ≤ a given time T.
We could pre-sort the finish times F_j. Since n ≤ 1000, we can for each i and each q compute m by scanning all F_j (O(n * a_i)), but a_i up to 150, n up to 1000 => 150k operations, which is trivial (150k). However, we need to compute for each i and each q: T = S_i+q-1, and count of F_j ≤ T. Since we have n up to 1000, and for each i, a_i up to 150, that's at most 150,000 queries. For each query, we could do binary search on sorted F list (including all jobs). So O(n * a_i * log n) ~ 100015010 = 1.5e6, also trivial.
But careful: For each i, we need to count F_j ≤ T, and we must exclude i? Actually i not finished, so its F_i > T, so it's automatically not counted. But if we include it, we would overcount. So we need to count only those j with F_j ≤ T. Since F_i > T, we can include all j and it's fine because it won't be counted. However, what if q = a_i? Then T = S_i + a_i - 1. F_i = S_i + a_i > T, so still not finished. So safe.
But wait: Could there be a scenario where a solution i is interesting because at some test q, the rounded percentage equals q, but the m count includes some solutions that finish exactly at time T? Since we count F_j ≤ T, that includes solutions finishing at T. As argued, for t in (L,R) where L = S_i+q-1, T = L, those completions are counted. That's correct because at any t > L, they are finished. So inclusion is correct.
Thus algorithm: compute F array sorted. For each i, for each q from 1 to a_i (if q > 100, skip because round(100m/n) ≤ 100; but we can still check but it's impossible). For each q, compute T = S_i + q - 1. Compute m = number of F_j ≤ T (using binary search on sorted F). Compute d = round(100m/n). If d == q, mark i as interesting and break (count once per solution).
Check if any edge cases: The caption displays "System testing: d%" where d is integer from 0 to 100. At the very beginning, before any solution finishes, m=0, d=round(0)=0. Could a solution be interesting with test q=0? No, tests start at 1. Also when all solutions are finished, m=n, d=100. But after a solution finishes, it's no longer being tested. So q could be 100 only if there is a test 100. That is possible if a_i ≥ 100.
Now we need to verify with examples.
Example 1:
n=2, k=2, a=[49,100].
Simulate: Both processes start at 0.
S1=0, F1=49.
S2=0, F2=100.
Compute S_i: For i=1:
q from 1 to 49, but we only care up to 100.
For i=2:
q from 1 to 100.
We need to check i=2, q=50? Actually example says at time 49.5, solution 2 is being tested on test 50, and caption says 50%. Let's compute:
For i=2, S2=0.
For q=50: T = S2 + 49 = 49? Actually q=50 -> T = S2 + 50 - 1 = 49. So T=49.
Now count F_j ≤ 49: F1=49 ≤ 49 yes, F2=100 no. So m=1.
d = round(100 * 1 / 2) = round(50) = 50. So q=50 matches. So i=2 is interesting. For i=1, q up to 49, check maybe? For q=49: T = S1+48 = 48? Actually S1=0, q=49 => T=48? Wait S1=0, q=49 => T = 0+49-1 = 48. F_j ≤ 48: none (F1=49 >48, F2=100 >48). m=0, d=0, not 49. Other q won't match. So only i=2 interesting. Output 1 matches.
Example 2:
n=4, k=2, a=[32,100,33,1].
Simulate schedule:
We have k=2.
Initialize heap: [0,0].
i=1: pop 0, S1=0, push 0+32=32.
i=2: pop 0, S2=0, push 0+100=100. Now heap: [32,100].
i=3: pop 32 (min), S3=32, push 32+33=65. Heap: [65,100].
i=4: pop 65 (min), S4=65, push 65+1=66. Heap: [66,100].
So S1=0,F1=32; S2=0,F2=100; S3=32,F3=65; S4=65,F4=66.
Now compute interesting.
Sorted F: [32,65,66,100].
Now for each solution:
i=1 (a1=32):
S1=0.
For q=1..32 (q≤100). Compute m = count(F ≤ T) where T = S1+q-1 = q-1.
- q=1: T=0, count ≤0: none? F1=32 >0, etc. m=0, d=round(0)=0, not 1.
- q=2: T=1, m=0, d=0 not 2.
...
- q=32: T=31, m=0, d=0 not 32.
No match.
i=2 (a2=100, S2=0):
q from 1 to 100.
We need to find q such that d = round(100m/n) = q, with m = count(F ≤ q-1).
Compute m as function of q: For q-1 < 32 => T<32 => m=0.
For 32 ≤ T < 65 => i.e., q-1 >=32 and <65 => q in [33,65]? Wait: T = q-1. So if q-1 >=32 and <65 => q ∈ [33,65]? Let's check: T=32 gives q=33? Actually q-1 = 32 => q=33. But careful: q is integer, T integer. When T=32, m includes F=32? Yes, because ≤32. So for T=32, m includes F1=32. So for q such that T = q-1 = 32 => q=33? That seems off: Let's compute systematically: For a given q, T = q-1. So if q=33, T=32. So m includes F1=32. So for q=33, m=1, d=round(1001/4)=round(25)=25, not 33. So we need d=q.
Now evaluate possible q:
- For q <=32? Actually T=q-1 <32 => m=0, d=0. So q would have to be 0 -> no.
- For q such that T in [32,64] => m=1 (since only F1=32 ≤ T, F3=65 not yet). So m=1 for q-1 ∈ [32,64] => q ∈ [33,65]. d=round(25)=25 constant. So q must equal 25, but 25 is not in [33,65]. So no.
- For q such that T in [65,65]? Actually T=65 => includes F1=32 and F3=65, so m=2. That's q = 66? Because T=65 => q=66. Also T in [66,?] let's check: T=66 => includes F1=32, F3=65, F4=66? Wait F4=66, so T=66 includes 32,65,66 => m=3. So:
q=66: T=65, m=2, d=round(50)=50, not 66.
q=67: T=66, m=3, d=round(75)=75, not 67.
q=68: T=67, m=3 (since 67 still ≤67? Actually F4=66, so T=67 includes 32,65,66 => m=3), d=75, not 68.
... up to q=100? We need to see when d equals q.
- For T ≥ 100? q up to 100, T max =99 for q=100. So T max =99. So never includes F2=100. So maximum T=99 => m=3 (since F1=32,F3=65,F4=66 ≤99). So for q from maybe 67 to 100, m=3 constant? Actually check: For T≥66, m=3 until T<100. So for q such that T≥66 => q-1 ≥66 => q≥67, and T<100 => q-1<100 => q≤100. So for q=67..100, m=3, d=75. So only d=75 for that range. None equals q.
But example says solution 2 is interesting (the second solution). They said at time 74.5 solution 2 is being tested on test 75, caption says 75%. So q=75, d=75. According to our calculation, for q=75, T=74, m= count(F ≤74). F1=32, F3=65, F4=66 all ≤74? 66 ≤74 yes, so m=3? Wait F4=66 ≤74 yes. So m=3, d=round(75)=75. So q=75 matches! I missed earlier: For q=75, T=74. Check T=74: which F's ≤74? F1=32, F3=65, F4=66 (66 ≤74 yes) => m=3. Indeed m=3, d=75, q=75. So solution 2 is interesting. But my earlier analysis said for q≥67, m=3, d=75, so q=75 works. So condition satisfied.
Now i=3 (a3=33, S3=32):
Compute for q from 1 to 33 (q<=33).
T = S3 + q -1 = 32 + q -1 = 31 + q.
Actually S3=32, so T = 32 + q -1 = 31 + q.
Now we need m = count(F ≤ T). Let's list F's: 32,65,66,100.
Now check q values:
We need d=round(100m/4)=? and compare to q.
According to example, solution 3 is interesting for q=25? They said: at time 32+24.5=56.5 the third solution is being tested on test 25, caption says 25%. So q=25. Let's verify.
For q=25, T = 31+25 = 56. Actually S3=32, q=25 => T = 32+24 = 56? Wait: T = S3 + q -1 = 32 + 24 = 56. So T=56. Count F ≤ 56: F1=32, F2=100 no, F3=65 no, F4=66 no. Only F1=32 ≤56 => m=1. d = round(1001/4) = round(25) = 25. So q=25 matches. So i=3 is interesting.
i=4 (a4=1, S4=65):
q=1 only. T = 65+0 = 65. Count F ≤ 65: F1=32, F3=65 => m=2? F4=66 not ≤65. So m=2, d = round(200/4)=round(50)=50. q=1 not 50. So not interesting.
Thus interesting solutions: i=2 and i=3 => count=2. Matches example.
Example 3: given output 5, we trust.
Thus our simplified condition appears correct.
Now we must confirm that m(t) is indeed constant over (S_i+q-1, S_i+q). This relies on all finish times being integers. We argued that because start times are integers, finish times are integers. But is it always true that start times are integers? Let's double-check: initial times are 0. When a process finishes at integer time, it can start a new job at that same integer time. So all start times are integers. Yes.
But what about the possibility that a process becomes idle at time t that is not integer? Could it happen? The processes run for integer durations, starting at integer times. So the next completion time after starting at integer t is integer. So all completion times are integer. So start times remain integers. So yes.
Edge case: If k > n, some processes never used; but start times are still integers.
Thus algorithm is straightforward.
Now we need to ensure we consider q from 1 to min(a_i, 100) because if q > 100, round(100*m/n) ≤ 100, so cannot equal q > 100. So we can skip q > 100. But what about q = 0? Not a test.
Now we need to count number of solutions that have at least one q meeting condition.
Implementation steps:
-
Read n, k.
-
Read array a[1..n].
-
Simulate schedule:
Use a min-heap (priority_queue<int, vector, greater>) pq.
For i in 0..k-1, push 0.
For i from 0 to n-1:
t = pq.top(); pq.pop();
S[i] = t;
pq.push(t + a[i]);
After loop, we have S[i] integers.
Compute F[i] = S[i] + a[i].
-
Sort F array (maybe we need original order for counting? We just need sorted list for binary search for each T).
-
For each i in 0..n-1:
interesting = false;
for q = 1 to a[i] (and q <= 100):
T = S[i] + q - 1;
m = number of F[j] <= T. Since F sorted, use upper_bound (or binary search) to get count.
d = round(100.0 * m / n). Compute as floor(100m/n + 0.5). Use integer arithmetic: d = (100 * m + n/2) / n? But careful with rounding: round(x) = floor(x+0.5). For integer division, we can compute d = (100m * 2 + n) / (2n)? Simpler: compute d = int(100.0 * m / n + 0.5). But to avoid floating errors, use integer: d = (100 * m + n/2) / n, using integer division rounding to nearest (ties round up? Actually floor(x+0.5) rounds half up. For positive numbers, (100m + n/2) // n gives floor((100m)/n + 0.5) because (100m + n/2)/n = 100m/n + 0.5. Taking floor yields rounding to nearest, with .5 rounding up. That's consistent with round function. But careful: For values exactly halfway, rounding to nearest integer (with ties rounding up) is what round does? The problem says round(x) = ⌊{x + 0.5}⌋, which is floor(x+0.5). That rounds .5 up. So using (100m + n/2) / n with integer division (floor) does exactly that because if 100m / n is exactly integer + 0.5, then 100m = n*(k) + n/2? Actually 100m = nk + n/2? But n may be odd, so n/2 not integer. In integer division, (100m + n/2) / n will produce the correct rounding because floor((100m)/n + 0.5). However, we need to be careful about integer overflow: 100m ≤ 1001000 = 100,000, safe. So we can compute d = (100*m + n/2) / n. Alternatively, use double and round; it's fine given small numbers. But integer is safer.
If d == q, then mark interesting and break.
-
Count interesting, output.
Now we must verify that the condition we derived (m = count(F_j ≤ S_i+q-1)) is valid for all cases, including when multiple completions occur exactly at time L = S_i+q-1. As argued, they are included. That's correct.
Now, is it possible that at some time inside the interval, m(t) could be different due to completions that occur at non-integer times? But we argued completions only at integer times, so inside an open interval (L,R) where L and R are integers, there are no integer times, so no completions. However, note: If S_i+q-1 is not integer? But S_i is integer, q integer, so L integer. So interval (integer, integer) contains no integers. So no completions inside. So m constant.
But wait, what if S_i is not integer? Could S_i be non-integer? Let's reexamine the scheduling rule: Processes start at time 0, and each test takes 1 second. So each test takes exactly 1 second, so each solution's total time is integer. However, when a process becomes free at time t (which might be integer), it takes the first solution from the queue and tests it on test 1 starting at time t. So start times are exactly the times when the process becomes free. Since initial free times are 0 (integer), and all durations are integer, the times when a process becomes free are sums of integers, hence integers. But is it possible that two processes become free at the same integer time and then one takes a job and the other takes the next; both start at that same integer time. So start times are integers. So indeed S_i integer.
Thus condition stands.
Now we must ensure we treat the case where k > n: initially we have k processes, but only n jobs. In simulation, we push k zeros; we pop for each job; if k > n, we still pop n times; the heap still contains extra zeros? Actually we should only push after assigning a job; we need to initialize heap with k zeros. Then for i from 1 to n, pop, assign start, push new finish time. That's fine.
Now edge cases: n=1. Then only one solution. Compute S1=0, F1=a1. For each q from 1 to min(a1,100): T = q-1. m = count(F_j ≤ T). Since only job not finished until T < a1? For T < a1, m=0, d=0. So q must be 0, impossible. For q = a1? T = a1-1, m=0, d=0. So not interesting unless maybe a1=0? but a_i ≥1. So interesting count 0? Possibly, but let's test: For n=1, k=1, a=100. At time 0 start testing. The caption starts at 0%. During test 1? m=0 => d=0, not 1. During test 100? At time 99.5, still m=0, d=0, not 100. After finishing, caption becomes 100% but solution no longer being tested. So no interesting. So answer 0. That seems plausible.
Now check if there is any scenario where m(t) might change during test interval due to completions that happen exactly at R? R is integer, but R is not included in the open interval. So not affecting. So constant.
Thus algorithm is solid.
Now we must ensure that we count each solution only once.
Time complexity: O(n log k + n * a_i log n) or even O(n * a_i) with linear scan because n small.
Now, we should double-check with example 3 to be sure.
But before finalizing, let's think about any nuance: The caption is computed as round(100*m/n). m is number of fully tested solutions by that moment. At time t, m(t) is the count of solutions j such that F_j ≤ t. In our reasoning we used m(t) = count(F_j ≤ L) for t in (L,R). But is it possible that at some t inside (L,R), a solution that started after L but before R could finish? That would require its finish time to be within (L,R). But finish times are integers. Since (L,R) contains no integers (as L,R integers and open interval), no solution can finish exactly at a non-integer time. So no.
Now, could a solution finish exactly at L? That's integer, and we include it because t > L. So m(t) includes it. That's correct.
Now, is there any subtlety about rounding? For m=0, d=0. For m=n, d=100.
Now, we should also consider that the caption might change at the moment when a solution finishes, but that moment is at integer times. But our interval (L,R) does not include those integer times if R is integer? Actually L and R are integers; the interval is open (L,R), which excludes both endpoints. So no change inside.
Thus algorithm stands.
Now we implement.
But wait: The problem statement says "There is a caption 'System testing: d%' on the page with solutions, where d is calculated as d = round(100⋅m/n), where round(x) = ⌊x + 0.5⌋ is a function which maps every real to the nearest integer." So for m/n = 0.5 exactly, d = round(50) = 50. Since we use integer arithmetic, we need to be careful about rounding. For example, if n=3, m=1, 1001/3 ≈ 33.333, round = floor(33.333+0.5)=33. So d=33. Using (100m + n/2)/n: (100+1)/3 = 101/3 = 33 (integer division truncates). That gives 33, correct. For m=2, (200+1)/3 = 201/3=67, correct? 2/3≈66.666, +0.5=67.166 floor=67. Yes. For n even, half: n=2,m=1: (100+1)/2 = 101/2=50 (since integer division truncates 50.5? Actually 101/2=50.5, integer division yields 50 because floor? Wait, in C++ integer division truncates towards zero for positive, so 101/2 = 50. But we need 50? Let's compute: 1001/2=50 exactly, round(50)=50. Our formula (100m + n/2)/n = (100+1)/2 = 101/2 = 50 (since 101/2=50.5, truncated = 50). That gives 50, correct. For m=0: (0+ n/2)/n = floor(0.5) =0? Actually (0 + 1)/2 = 0? 1/2=0 in integer division, so 0. Good. For n odd, n/2 truncates; but is that correct? For m such that 100m/n is exactly .5, say n=3,m=1? 100/3≈33.333 not .5. Actually .5 occurs when denominator 2? For rounding to nearest, we need to add 0.5. In integer arithmetic, we can compute (2100m + n) // (2n) maybe? But simpler: use double: int(100.0m/n + 0.5). However, double precision is fine. But integer method: d = (100m + n/2) / n works because we want floor(100m/n + 0.5). Let's derive: floor(100m/n + 0.5) = floor((100m + 0.5n)/n) = floor((2100m + n) / (2n)). But dividing by n after adding n/2 is not equivalent exactly due to integer division? Actually we want to compute floor(x + 0.5) where x = 100m/n. Let y = 100m. Then x + 0.5 = (y + 0.5 n)/n = (2y + n)/(2n). Taking floor of that rational. Alternatively, we can compute d = (y * 2 + n) / (2 * n) using integer division. But easier: d = (100 * m + n/2) / n using integer division? Is that equal to floor((100m)/n + 0.5)? Let's test with n=3, m=1: (100 + 1)/3 = 101/3 = 33 in integer division (since 333=99, remainder 2). floor(33.666? Actually (100+1)/3 = 33.666? Wait, 101/3 ≈33.666, integer division gives 33. But floor(33.666)=33. But we need floor(33.333+0.5)=floor(33.833)=33. So 33 matches. Good.
Test with n=3, m=2: (200 + 1)/3 = 201/3=67, floor(66.666+0.5)=67, correct.
Test with n=5, m=2: 1002/5=40, round=40. (200 + 2)/5=202/5=40 (since 405=200), correct.
Test with n=5, m=3: 300/5=60, round=60. (300+2)/5=302/5=60, correct.
Now test borderline: n=2,m=1: (100+1)/2 = 101/2 = 50 (int division), correct.
Now test n=2,m=0: (0+1)/2=0, correct.
Now test n=1,m=0: (0+0)/1=0? n/2=0, correct. m=1: (100+0)/1=100, correct.
Thus integer method works.
Now we need to check if any solution could be interesting with q > a_i? Not possible.
Implementation details:
- Use vector a(n), S(n), F(n). Use a min-heap (priority_queue<int, vector, greater> pq.
- Initially push 0 k times.
- For i in 0..n-1: t = pq.top(); pq.pop(); S[i]=t; pq.push(t + a[i]).
- Then compute F[i] = S[i] + a[i].
- Sort F into vector sortedF = F.
- For each i: for q = 1 to min(a[i], 100): T = S[i] + q - 1; m = upper_bound(sortedF.begin(), sortedF.end(), T) - sortedF.begin(); because we count F_j ≤ T. Since sortedF includes all F's, including i's own F_i, but F_i > T (since T = S_i+q-1 ≤ S_i + a_i -1 < F_i), so it doesn't count. So okay.
- d = (100 * m + n/2) / n.
- if d == q: mark interesting, break.
Potential pitfalls: The schedule we compute via priority queue may produce S_i that are not exactly as described? Let's test with a more complex scenario to ensure that S_i are indeed integers and correct. Since we push t + a_i where t and a_i are integers, we get integer. So fine.
Now, we must consider if there is any scenario where S_i could be not integer because of ties? No, because all a_i integers, t integer, so sum integer.
Now, is there any scenario where multiple processes free at time t, and the heap gives the smallest time (t) but there could be multiple with same time. The heap pop returns the smallest, but if there are multiple with same smallest, it might return one arbitrarily. However, as argued, start times are unique. But does the assignment order affect S_i for later jobs? According to our earlier reasoning, the set of start times is unique. But let's test with a scenario to verify that the S_i computed by always popping the smallest (and thus assigning to the process that finished earliest) yields the same S_i as any other assignment that respects FIFO? For example, n=3, k=2, a=[5,5,1]. At time 0, both free. Using our heap (which stores available times), we pop 0 (say process1) assign job1, push 5; then pop next 0 (process2) assign job2, push 5. Now heap has {5,5}. For job3, we pop 5 (either), assign S3=5, push 6. So S3=5. If instead we assigned job1 to process1 and job2 to process2 but then at time 5 both become free simultaneously. The next job (job3) would start at 5. So same.
But what if durations differ? n=3,k=2,a=[2,3,1]. At time 0, assign job1 to proc1 (finish at 2), job2 to proc2 (finish at 3). At time 2, proc1 free and takes job3, start at 2, finish at 3. That gives S3=2. If we initially assigned job1 to proc2 and job2 to proc1, then at time 0, both start. Proc1 finishes job2 at 3? Actually if job2 (a=3) assigned to proc1, and job1 (a=2) to proc2, then at time 2 proc2 free, takes job3 start at 2. So S3=2 again. So same.
What about a scenario where at time 0 there are more than k jobs? Not possible because we process sequentially. The order of assignments when multiple free at same time does not affect the start times because jobs are taken from the queue in order and all start at that same time. The only thing that could differ is which processor gets which job, but as argued, the multiset of finish times after processing the first k jobs is the same regardless of assignment (since the jobs are assigned to the k processors, the set of their durations determines the finish times). Then for subsequent jobs, the start time is the minimum finish time among processors, which is determined by the multiset. So start times are unique. So our simulation with a min-heap yields a valid schedule, and start times are unique (though not necessarily the same as any possible schedule? But since all valid schedules produce the same start times? I think they do because the system is deterministic in terms of start times: the order of jobs is fixed, and we always assign the next job to the processor that becomes free the earliest. In any valid schedule, at any time when a processor becomes free, if there is a job waiting, it will start immediately. There's no idle time if there are jobs waiting. The only decision is which processor gets which job when multiple become free simultaneously and multiple jobs waiting. But if multiple become free at same time, all of them will start jobs immediately, and the set of jobs started at that time is the next set of waiting jobs. The assignment of specific jobs to processors may affect which processor finishes later, but the start times of those jobs are all that same time. For the subsequent job, its start time is the earliest time any processor becomes free after that. That earliest time is the minimum of the finish times of the jobs that just started. That minimum might depend on which job was assigned to which processor? Actually if two jobs start at time t on two processors, their finish times are t + a_i and t + a_j. The minimum of these two numbers is min(t + a_i, t + a_j) = t + min(a_i, a_j). If we swap assignments, the set of finish times is still {t + a_i, t + a_j}. The minimum remains t + min(a_i, a_j). So the start time of the next job is determined solely by the set of durations of the jobs started at that time, not by which processor gets which. So it's unique. So S_i are unique