We are given T test cases. For each, N and array B of N integers. We need to determine if there exists a valid statistic A (real numbers) such that sum_i A_i = 100, and after "rounding up" each A_i (non-integer rounds up to next integer; integers stay as they are) we get exactly B_i. We need output YES or NO.
Interpretation: For each i, we need to have: if A_i is integer, then A_i = B_i; if A_i is not integer, then floor(A_i) = B_i - 1? Actually "rounded up to next integer": For non-integer, we take ceil(A_i). That's the standard ceiling function. For integer, it stays same, which is also equal to ceil(integer). Actually ceil(integer)=integer. So the rounding operation described is exactly the ceiling function! But careful: They say: If Ai is not an integer, it will be rounded up to next integer. Otherwise it will be left as it is. So indeed rounding up of a real number is: ceil(A_i). So after rounding, we get B_i = ceil(A_i). And we also require that sum_i A_i = 100 exactly.
Thus the problem reduces to: Given integer array B_i (>=0), does there exist real numbers A_i such that:
- ceil(A_i) = B_i for all i,
- sum_i A_i = 100.
Additionally, we may have constraints about A_i being "statistics" percentages? They can be any real numbers? Possibly negative? But "Ai percent of people voted for opinion number i" suggests percentages, so typically between 0 and 100, but could be any nonnegative? Usually percentages are nonnegative and sum to 100. So we can assume A_i >= 0? But not explicitly stated; but "valid if sum of all Ai is equal to 100" - no nonnegativity mentioned, but typical percentages nonnegative; but it may be necessary to assume nonnegative because they represent percentages. However, we may need to check: Does the problem require Ai to be >=0? It says "Sereja conducted a voting about N of his opinions. Ai percent of people voted for opinion number i." So indeed Ai are percentages, so should be between 0 and 100, inclusive? Typically percentages are nonnegative and sum to 100. Not necessarily integer. So we should assume A_i >= 0. They might allow small negative? Not realistic. I'll assume Ai >= 0. But do we need to enforce? The condition sum to 100 and ceil(Ai)=Bi; Bi are given as integers between 0 and 1000, but might be >100? Possibly. But if Bi >100, that could force Ai >100? Actually Ai percent can be >100? Not possible; sum of percentages is 100, and each percent is at most 100. So each Ai must be between 0 and 100. So we also have 0 <= Ai <= 100. But we can consider these constraints later if needed.
However, the problem likely expects only the condition from ceil and sum; I think nonnegativity is automatically enforced by Bi >=0? Possibly not: if Bi = 0, then Ai could be negative? But Ai percent negative doesn't make sense. So we must also have Ai >= 0. But we can examine test cases.
Given constraints: Bi up to 1000, but N up to 10000, sum of Bi could be large. But note that if sum of Bi is less than 100? Then maybe we can fill? Let's think.
We need to find A_i such that:
- B_i - 1 < A_i <= B_i, if A_i is not integer? Actually careful: For a real number x, ceil(x) = b (integer) means b-1 < x <= b, with the condition that if x is exactly integer b, then ceil(x)=b as well. So the condition "ceil(x) = b" is equivalent to: b-1 < x <= b, but also if x = b exactly, that's allowed. However, if x = b-0.5, ceil is b, ok; if x = b-0.0001, ceil is b. So condition is: x ∈ (b-1, b] with the nuance that if x is exactly b, it's ok. But wait: If x = b exactly, ceil(x)=b, that's included. So overall condition: b-1 < x ≤ b, with the exception that if x is integer b? It's included. But the inequality b-1 < x ≤ b already includes x = b. So it's exactly that: x ∈ (b-1, b]. However, does this also capture the "non-integer rounding up" nuance? For x integer b, ceil(b)=b, so ok. For x integer b-1? If x = b-1 exactly, ceil(b-1) = b-1, not b. So x = b-1 is not allowed because then ceil would be b-1, not b. So x cannot be exactly b-1 unless b-1 is integer, but then ceil would be b-1. So indeed the condition is strictly greater than b-1. So we have: A_i ∈ (B_i - 1, B_i] for each i, with the added nuance that if B_i = 0, then lower bound is -1? Actually B_i=0 => ( -1, 0] but A_i cannot be negative? Also A_i must be >=0. So for B_i = 0, we require A_i ∈ ( -1, 0] and also A_i >=0 => A_i = 0 (exactly) because positive? Actually ( -1, 0] includes 0, but does it include 0? Yes, includes 0 because ≤0. But also > -1. So A_i can be 0 exactly. But can A_i be something like -0.5? -0.5 ∈ (-1,0] and would give ceil(-0.5)=0? Ceil of -0.5 is 0? Actually ceil(-0.5)=0 because rounding up to next integer? Ceil function: ceil(-0.5) = 0. Yes, that's correct. But A_i being negative percent doesn't make sense. So we must enforce A_i >= 0. So we should restrict to nonnegative A_i. So for B_i = 0, A_i must be 0? Actually could be 0, or could be any number between 0 and 0? The interval ( -1,0] includes numbers like -0.1, -0.5, 0. But negative numbers are not allowed (since percentages). So only 0 is allowed. Also any positive number less than 0? There is none. So effectively A_i = 0.
But what about B_i > 0? Lower bound is B_i -1. Could be negative if B_i = 0? Already addressed. For B_i = 1, interval (0,1] includes numbers like 0.1,0.5,0.999,1. So lower bound is >0, so nonnegative automatically. For B_i >=1, lower bound B_i-1 >=0, so all numbers in interval are >=0 (strictly > B_i-1 >=0, except maybe B_i=1 gives >0, okay). So nonnegativity is automatically satisfied for B_i>=1 (since any number >0 is >=0). However, if B_i=0, then only 0 is possible.
So the only extra condition is that for B_i=0, A_i must be exactly 0. Because if we allow negative percentages it's unrealistic, but problem likely assumes percentages nonnegative, so we should enforce A_i >=0. I think we can adopt that.
Thus we need to find real numbers A_i ∈ I_i, where I_i = (B_i - 1, B_i] if B_i > 0, and I_i = {0} if B_i = 0 (or maybe [0,0]), such that sum_i A_i = 100.
Now is there any other condition? "Valid if sum of all Ai is equal to 100." No other conditions. So the existence is about whether 100 lies within the sum of these intervals.
Specifically, let lower_i = B_i - 1 (but strict >), and upper_i = B_i. However, because of strict lower bound, the sum set of intervals (the Minkowski sum) will be an open interval on the left? Actually each A_i can be arbitrarily close to B_i - 1 from above, but cannot equal B_i - 1 exactly, except possibly when B_i = 0? We'll handle strictness carefully. Since we need existence of some exact A_i values, we need to check if there exists a combination such that sum exactly = 100. Because intervals are continuous, the set of possible sums is an interval (maybe open at some ends) from sum of lower bounds (if we take infimum) to sum of upper bounds, but because each A_i can approach its lower bound arbitrarily close (but not equal), the infimum of possible sums is sum_i (B_i - 1) (but not attainable if any B_i -1 is not allowed due to strictness, unless B_i -1 is not allowed because it's strict). However, if for some i, the lower bound is strict, the sum cannot be exactly equal to that infimum if any such strict component can't be exactly its lower bound. But we can get arbitrarily close from above. Similarly, the supremum is sum_i B_i, which is attainable because we can set each A_i = B_i exactly (since integer B_i is allowed; and if B_i is integer, A_i = B_i is in the interval because B_i ≤ B_i and > B_i-1? B_i = B_i is allowed, yes). So maximum sum = sum B_i is attainable (if all A_i = B_i). Minimum sum is not necessarily attainable but we can get as close as we want to sum(B_i -1) = (sum B_i) - N. Actually careful: For each i, the minimum possible A_i is just above B_i - 1. So the infimum of possible sum is S_low = ∑ (B_i - 1) = (∑ B_i) - N. But this infimum is not necessarily achievable, because to achieve exactly that sum, we would need each A_i = B_i - 1 exactly, which is not allowed (except when B_i -1 is allowed? When is B_i -1 allowed? Only if B_i -1 is not integer? Actually condition: A_i must be > B_i -1. If B_i -1 is not integer? Wait, the condition is "if Ai is not integer, it will be rounded up to next integer; otherwise it will be left as it is." The rounding operation defined is ceil. Ceil(x)=B_i means x in (B_i-1, B_i] with the special case that if x = B_i (integer) allowed. So for any x = B_i-1 exactly, ceil(B_i-1) = B_i-1, not B_i, so it's not allowed. So regardless of whether B_i-1 is integer or not, x = B_i-1 yields ceil = B_i-1, not B_i. So it's not allowed. So indeed each A_i cannot be exactly B_i-1. So the lower bound is open. So the minimum possible sum is > (∑ B_i) - N, but we can approach arbitrarily close. So the set of achievable sums is an interval: (S_low, S_high] or maybe [something, S_high] if we can achieve S_low? But we can't achieve S_low because it's open at each component, but it's possible that some components can be exactly at lower bound? No, none can. But if N=0? Not possible. So the achievable sum set is: { sum_i A_i : A_i ∈ I_i } = (∑ (B_i -1), ∑ B_i] ??? But is it always an interval? Since each I_i is connected (an interval that is open at left, closed at right), the Cartesian product is connected, and summation is continuous, so the image is also a connected subset of R, i.e., an interval. The interval will be from the infimum of sums to the supremum, but may be open or closed at the ends. Since we cannot achieve the infimum (strict lower bound for each coordinate, and for each coordinate we can approach arbitrarily close, but the infimum is not achieved because to achieve it, all A_i must be exactly at the lower bounds, which is not allowed). However, if some I_i have lower bound that is actually achievable? For B_i=0, I_i = {0}. In that case, lower bound is 0 exactly, which is achievable. But for B_i>0, it's open. So if there is at least one i with B_i>0, then the infimum might not be achievable because that component cannot be exactly its lower bound. But could the infimum be achieved by compensating with other components? Suppose we try to achieve sum exactly S_low. To get S_low, we need ∑ A_i = ∑ (B_i -1). Since each A_i ≥ something > B_i-1? Actually for those with B_i>0, we need A_i > B_i-1. For those with B_i=0, we have A_i = 0 exactly, which equals B_i -1? B_i-1 = -1, but A_i=0 is not equal -1. So they are above lower bound. So even if some have B_i=0, they are strictly greater than B_i-1 (since B_i-1 = -1, and A_i=0 > -1). So all A_i > B_i-1 strictly. So sum > ∑ (B_i-1). So S_low is not achievable. However, if all B_i = 0? Then N would have to be something? But sum of percentages must be 100, impossible if all B_i=0. So at least some B_i>0. So infimum not achievable.
Thus the set of achievable sums is (L, U] where L = ∑ (B_i -1) and U = ∑ B_i, provided L < U. But is it always exactly that? There might be constraints about some A_i being exactly at B_i (upper bound) or any interior points. Since we can vary continuously, any sum between L and U should be achievable? Not necessarily: Because intervals are open on left, but we can approach arbitrarily close to L. For any target sum S in (L, U], can we find A_i ∈ I_i summing to S? Usually yes because we have continuous degrees of freedom and the intervals are convex, the sum set of open-closed intervals is an interval (possibly open at left). However, we need to verify that the entire interval (L, U] is achievable. There is a known result: The sum of intervals (a_i, b_i] (with a_i maybe -infinity) yields an interval (∑ a_i, ∑ b_i] if at least one interval has open left endpoint? Actually the sum of open intervals can be open at the left if all left endpoints are open. But we also need to consider that the left endpoints are open but we can approach arbitrarily close; and the right endpoints are closed so we can achieve the max. For any S in (∑ a_i, ∑ b_i], we can choose A_i appropriately, because we can start from all A_i = b_i, then decrease some to approach the lower bound as needed. Since we have N degrees of freedom, we can adjust continuously. However, there is a subtlety: For B_i=0, the interval is {0} which is closed (both ends). That's degenerate. But still, the sum of intervals should be a closed or half-open interval? Let's reason.
Consider we have variables with constraints: For each i, A_i ∈ [L_i, U_i] but with L_i maybe not included (strictly >). Actually for B_i>0, L_i = B_i-1 (excluded), U_i = B_i (included). For B_i=0, L_i=U_i=0 (included). For B_i>0, can we get arbitrarily close to L_i from above? Yes. So the feasible region for each is a half-open interval (L_i, U_i]. The Cartesian product is not closed but is connected. The sum function is continuous, so the image is connected, thus an interval. The maximum is ∑ U_i, attained by taking each at U_i. The minimum is not attained, but the infimum is ∑ L_i. For any S in (∑ L_i, ∑ U_i], we can achieve S. Is there any gap? Typically, the image of a continuous function from a connected set is connected, so it must be an interval. Since we know the set contains values arbitrarily close to ∑ L_i from above and contains ∑ U_i, the image must be (∑ L_i, ∑ U_i] (if it's exactly that interval). However, we must check if the interval could be closed at the left? It cannot be closed because the infimum is not attained. So it's open at left. Thus for any S > ∑ L_i and S ≤ ∑ U_i, S is achievable. So condition for existence of A_i such that sum = 100 is: 100 > ∑ (B_i - 1) and 100 ≤ ∑ B_i. In other words:
∑ B_i - N < 100 ≤ ∑ B_i.
But careful: This condition does not consider the special case B_i=0? But for B_i=0, B_i-1 = -1, so ∑ (B_i -1) becomes sum B_i - N. That's still correct because those terms contribute -1. But the lower bound for A_i for B_i=0 is actually 0, but we used -1? Wait: For B_i=0, we said A_i must be exactly 0 (nonnegative). In our interval derivation, we used the interval (B_i -1, B_i] = (-1, 0]. But we also require A_i >=0, which restricts to [0,0]? Actually nonnegativity says A_i must be >=0. So feasible set is (-1,0] ∩ [0, ∞) = {0} (just 0). So the lower bound effectively becomes 0, not -1. However, the interval (-1,0] includes numbers >0? No, ≤0. The intersection with nonnegative yields only 0. But the condition sum A_i = 100 forces some positive contributions; B_i=0 forces A_i=0 exactly. So for B_i=0, A_i cannot be any number greater than -1 but less than 0; those are negative and not allowed. So the effective lower bound for such i is 0, and also the upper bound is 0. So it's a fixed value 0. So the interval becomes degenerate {0}.
Now does our condition ∑ B_i - N < 100 ≤ ∑ B_i still hold if we treat those B_i=0 as contributing -1 to the lower bound? That would give a lower bound that could be less than what is actually achievable because the true lower bound for those i is 0, not -1. For example, suppose we have N=1, B_1=0. Then according to our condition, ∑ B_i = 0, ∑ B_i - N = -1. Condition would say need -1 < 100 ≤ 0, which is false because 100 ≤ 0 false. So condition says NO, which is correct because you cannot have A_1=100 with B_1=0? Actually can we have A_1 such that ceil(A_1)=0 and sum A_1=100? Ceil(A_1)=0 means A_1 ≤0? Because ceil(x)=0 implies x ∈ (-1,0]? Actually ceil(x)=0 implies x ∈ (-1,0]. But also x must be 100? Not possible. So indeed NO. So condition works.
But what about B_i=0 among others? Consider N=2, B = [0, 100]. Then ∑ B_i = 100, ∑ B_i - N = 100 - 2 = 98. Condition: 98 < 100 ≤ 100? Yes, because 100 ≤ 100 is true. So condition says YES. But is there a valid A? Need A1, A2 such that ceil(A1)=0, ceil(A2)=100, sum=100. For B1=0, A1 must be exactly 0 (nonnegative). So A1=0. Then A2 must be such that ceil(A2)=100 and sum=100 => A2=100. But ceil(100)=100, ok. So A=[0,100] works. So condition yields YES, which is correct.
Now consider N=2, B=[0, 101]. ∑B = 101, ∑B-N = 101-2=99. Condition: 99 < 100 ≤ 101, true. Is there valid A? B1=0 forces A1=0. B2=101 requires A2 ∈ (100,101] and sum must be 100 => A2=100? But A2 must be >100? Actually ceil(A2)=101 means A2 ∈ (100,101]. So A2 must be >100 and ≤101. But A1+A2 = 0 + A2 = 100. So A2 = 100. But 100 is not >100, it's equal to 100. And ceil(100)=100, not 101. So not allowed. Also can't be less than 100 because sum would be less. So no valid A. So condition incorrectly says YES. So our condition fails when there is a B_i=0 because the lower bound for that variable is 0, not -1. However, our earlier derivation of condition assumed each variable can take values arbitrarily close to B_i-1. For B_i=0, B_i-1=-1, but the feasible values are not in (-1,0] unrestricted because of nonnegativity? Actually the problem statement didn't explicitly say A_i must be nonnegative. It said "Ai percent of people voted for opinion number i." That implies nonnegative. Usually percentages are between 0 and 100 inclusive. So we must enforce nonnegativity. But did the problem statement mention nonnegativity? Not explicitly. But typical context: percentages are nonnegative. However, is it possible that the problem expects that A_i can be any real numbers, including negative? That would be weird: negative percent? So I think we must consider A_i >= 0.
Let's check the test cases: They gave example: 3: 30 30 30 -> N=3, ∑B=90, ∑B-N=87. Condition: 87 < 100 ≤ 90? 100 ≤ 90 false -> NO, matches. 4: 25 25 25 25 -> ∑B=100, ∑B-N=96, condition: 96<100≤100 true -> YES matches. 2: 50 51 -> ∑B=101, ∑B-N=99, condition: 99<100≤101 true -> YES matches. Those are consistent.
But what about a case like [0,101]? We found condition says YES, but is that actually valid? Let's think: N=2, B=[0,101]. Is there A1, A2 real numbers such that ceil(A1)=0, ceil(A2)=101, sum=100? Ceil(A1)=0 means A1 ∈ (-1,0]. Without nonnegativity, we could pick A1 = -0.5 (negative). Then ceil(-0.5)=0? Ceil(-0.5) is 0 indeed. Then we need A2 such that ceil(A2)=101 and A1+A2=100 => A2=100.5. But ceil(100.5)=101? Yes, because 100.5 rounds up to 101. So A2=100.5. Check: A2=100.5, ceil=101. A1=-0.5, ceil=0. Sum=100. So this is a valid solution if we allow negative percentages. But does it make sense? Probably not, but maybe the problem doesn't require nonnegativity? The problem statement says "Ai percent of people voted for opinion number i." That implies Ai should be a percentage, which can't be negative. However, sometimes in such problems they don't restrict to nonnegative unless stated. Let's read problem statement: "Sereja conducted a voting about N of his opinions. Ai percent of people voted for opinion number i. This statistics is called valid if sum of all Ai is equal to 100." That's it. It doesn't say Ai must be nonnegative. But the phrase "percent" typically implies between 0 and 100, but sometimes in contest problems they might ignore that nuance and just treat Ai as real numbers. However, they also define rounding up: if Ai is not integer, it will be rounded up to next integer; otherwise it will be left as it is. The rounding operation defined is ceil. The Bi given are integers between 0 and 1000. They ask: whether there exists some valid statistic A such that after rounding it up, it becomes same as B? It does not explicitly say Ai must be between 0 and 100. Could they be any real numbers? Let's think: If Ai can be negative, then the concept of "percent" is odd, but mathematically the problem might still be well-defined, and they might not have added nonnegativity constraint. The test case [0,101] is not given. We need to decide based on typical problem constraints. Many problems of this type exist: Given rounded percentages (rounded up), does there exist original percentages summing to 100? They often allow any real numbers, sometimes even negative, but I'm not sure.
Let's check if any constraints might force nonnegativity: In input, Bi are between 0 and 1000. They could be 0, so Ai could be negative? Possibly. But if Ai is negative, ceil(Ai) could be 0 if Ai ∈ (-1,0]. So Bi=0 could correspond to negative Ai. That seems plausible. But does that cause any issues? The sum of percentages is 100, so some could be negative to offset larger values? That could be allowed mathematically, but would it be considered a valid statistic? Usually no. However, problem setter might not have thought about that corner; they might have assumed Ai are nonnegative implicitly. But typical rounding problems often consider that percentages are between 0 and 100, and after rounding they sum to something else. For example, "percentage rounding up" problems: given rounded percentages that sum to 100 or 101, etc. This one is about existence of original percentages that round up to given integers and sum to exactly 100. I've seen similar problems: Given integers B_i, does there exist real numbers A_i such that sum A_i = 100 and ceil(A_i) = B_i? The necessary and sufficient condition is that sum B_i - N < 100 ≤ sum B_i. That is a known result. And indeed the test cases match that condition. And the problematic [0,101] would satisfy the condition, and indeed there is a solution with negative A1. So if the problem intended nonnegativity, they would have to adjust condition: need also that for each i, B_i must be at least something? Actually if we require Ai ≥ 0, then for Bi = 0, we must have Ai = 0 (since Ai cannot be negative). So then the condition becomes: There exists Ai ∈ [0, B_i]? Wait for Bi>0: Ai ∈ (Bi-1, Bi] and also Ai ≥ 0 automatically if Bi-1≥0? For Bi=1, (0,1] ok. For Bi=0, only Ai=0. So effectively, the feasible interval for each i is [L_i, U_i] with L_i = max(0, Bi-1)?? Actually for Bi≥1, lower bound is Bi-1 (strict > but we can consider open). For nonnegativity, we don't need to change lower bound because Bi-1≥0 for Bi≥1, so the interval (Bi-1, Bi] is already nonnegative. For Bi=0, the interval is {0}. So if we incorporate nonnegativity, the lower bound effectively becomes Bi-1 if Bi>0, and 0 if Bi=0. But careful: For Bi>0, the interval is (Bi-1, Bi], which is a subset of [0, ∞) because Bi-1≥0? Not if Bi=0? Already handled. If Bi=1, then Bi-1=0, but interval is (0,1], so does not include 0. So 0 is not allowed for Bi=1 because if Ai=0, ceil(0)=0, not 1. So indeed for Bi=1, Ai must be >0. So that's fine.
Now with nonnegativity, the condition for existence becomes: we need to find Ai ∈ I_i (with I_i as described, but with strict > lower bound for Bi>0) such that sum = 100. The set of achievable sums is more restricted. Let's denote for each i:
- If Bi = 0: Ai must be exactly 0.
- If Bi > 0: Ai ∈ (Bi-1, Bi].
Thus the possible sums range from S_min_possible to S_max, where S_min_possible = sum_{Bi=0} 0 + sum_{Bi>0} (Bi-1 + epsilon) i.e., strictly greater than sum_{Bi>0} (Bi-1), but we can approach arbitrarily close to that sum from above. S_max = sum_{Bi} Bi, attainable by setting Ai = Bi for all i (which is allowed, since Bi integer and ceil(Bi)=Bi). But also note that for Bi>0, Ai can be exactly Bi, which is allowed.
So the achievable sums are: S ∈ ( L', U ] where L' = sum_{Bi>0} (Bi-1) (since Bi=0 contribute 0) but is that open? Because each term with Bi>0 cannot be exactly its lower bound; thus the infimum is L' but not attainable. So any S > L' and S ≤ U is achievable? But we must check if there is any gap due to the strict lower bounds and the fact that the intervals are half-open. Since we have continuous degrees of freedom, we should be able to achieve any S in (L', U] by adjusting values. However, is there any further restriction when some Bi=1? Then lower bound is 0 but not inclusive. So we can make Ai arbitrarily close to 0 from above. That's fine.
But also consider Bi=0: they are fixed to 0, so they don't provide flexibility.
Thus condition with nonnegativity is: 100 > sum_{Bi>0} (Bi-1) and 100 ≤ sum_{Bi} Bi. That is 100 > (∑{i} Bi) - (number of Bi>0) and 100 ≤ ∑ Bi. Because sum{Bi>0}(Bi-1) = (∑ Bi) - (# of indices with Bi>0). Let M = number of i such that Bi > 0. Then condition: ∑ Bi - M < 100 ≤ ∑ Bi.
But if we allow negative Ai (no nonnegativity), the condition is ∑ Bi - N < 100 ≤ ∑ Bi. Since N ≥ M, the condition with nonnegativity is stricter because ∑ Bi - M is larger than ∑ Bi - N (since M ≤ N). So the condition with nonnegativity would be more restrictive. For test case [0,101], ∑Bi=101, N=2, M=1 (since one Bi>0), ∑Bi - M = 100. Condition: 100 < 100 ≤ 101? The inequality is strict: need 100 > ∑Bi - M? Actually we need 100 > ∑Bi - M (since strictly greater) and 100 ≤ ∑Bi. ∑Bi - M = 101-1=100, so 100 > 100 is false. So it would say NO, which matches the intuitive expectation that there is no nonnegative solution. So the nonnegative condition yields NO for [0,101], while the unrestricted condition yields YES. So which one is likely intended?
Let's examine other potential edge cases. Consider B = [0,0,...,0,100] with many zeros. For N large, ∑Bi - N could be negative large, so condition ∑Bi - N < 100 always true. But if we require nonnegativity, we need 100 > ∑Bi - M, where M is number of positive entries. If there is only one positive entry (say 100) and many zeros, then ∑Bi - M = 100 - 1 = 99, condition 100 > 99 true, and 100 ≤ 100 true => YES. That's fine: we can set that positive Ai = 100, zeros to 0. Works. If positive entry is 101 and zeros, ∑Bi=101, M=1 => ∑Bi - M = 100, condition 100 > 100 false => NO. So no solution with nonnegative. Unrestricted would allow solution with negative zeros? But zeros are B_i=0; if we allow negative, then we can set some zeros to negative values to offset the extra 1. For example, one B=101 and one B=0: A1=100.5, A2=-0.5 works. So unrestricted says YES. Which one is plausible?
The problem statement: "Ai percent of people voted for opinion number i." This strongly suggests Ai are percentages, i.e., between 0 and 100 inclusive. Also the sum of Ai is 100. So they should be nonnegative and likely also ≤100? But they didn't explicitly say ≤100, but if Ai > 100, then the sum of all Ai being 100 would force others to be negative. But Ai >100 could happen if others negative? But since percentages usually nonnegative, each Ai should be between 0 and 100. However, is that enforced? The rounding up: ceil(Ai) = Bi, and Bi can be up to 1000. Could Ai be >100? Possibly if Bi >100, then Ai > Bi-1. If Bi = 101, then Ai ∈ (100,101]. That could be >100, but then sum of all Ai is 100, so some others must be negative to compensate. If we require all Ai ≥ 0, then having a Bi > 100 would force Ai >100, but then sum of all Ai >100 (since others ≥0) unless others are negative. So with nonnegativity, it's impossible to have any Bi > 100 if sum of Ai = 100 and all nonnegative? Actually if one Ai > 100, then sum > 100 even if others zero, so cannot sum to 100. So under nonnegativity, we must have each Bi ≤ 100? Not necessarily, because Ai could be exactly 100 if Bi=100, but if Bi=101, Ai must be >100, so sum would exceed 100 if others nonnegative. So under nonnegativity, any Bi > 100 makes solution impossible. But the problem constraints allow Bi up to 1000. So they anticipate that Bi may exceed 100. However, could there be a solution with Bi > 100 under nonnegativity? Only if some other Ai are negative? No. So if we enforce nonnegativity, any test case with Bi > 100 would be automatically NO? Not necessarily, because you could have multiple Bi > 100? Still sum would exceed? Let's examine: Suppose N=2, B=[101, -? but Bi can't be negative, min 0]. Sum of Bi would be >100, but under nonnegativity, each Ai is at most Bi? Actually Ai ≤ Bi, but can be less. But for Bi=101, Ai > 100, so >100. If another Ai is positive, sum >100+ something. If another Ai is 0, sum >100. So indeed impossible to sum to 100 if any Bi > 100, because each Ai > Bi-1 ≥ 100? Actually Bi > 100 implies Bi >= 101, then lower bound is >100? Bi-1 >= 100, and since Ai > Bi-1, Ai > 100. So that one alone exceeds 100. So sum > 100. So under nonnegativity, any Bi > 100 leads to NO. But the problem didn't exclude such cases; they are allowed. But many problems might allow them and the condition ∑Bi - M < 100 ≤ ∑Bi would detect impossibility because if Bi >100, then ∑Bi is at least 101, and ∑Bi - M might be >100? Not necessarily. For example, B=[101,0] => ∑Bi=101, M=1, ∑Bi-M=100. Condition: 100 > 100? false, so NO. So nonnegativity condition gives NO. So that is consistent.
What about B=[101,1]? ∑Bi=102, M=2, ∑Bi-M=100. Condition: 100 > 100? false, NO. Under unrestricted, ∑Bi - N = 102-2=100, condition: 100 > 100? false, so also NO. Actually unrestricted would require 100 > ∑Bi - N = 100, false. So both say NO. So maybe both conditions could coincide sometimes.
Let's try B=[102, -?]. Unrestricted: ∑Bi-N = 102-2=100, 100>100 false -> NO. Nonneg: M=2, ∑Bi-M=100, 100>100 false -> NO. So same.
Now try B=[100,1]? ∑Bi=101, N=2, ∑Bi-N=99, 100 > 99 true, 100 ≤ 101 true -> YES unrestricted. Nonneg: M=2, ∑Bi-M=99, same -> YES. So same.
Now B=[100,0]? ∑Bi=100, N=2, ∑Bi-N=98, 100 > 98 true, 100 ≤ 100 true -> YES unrestricted. Nonneg: M=1 (since B2=0 not >0), ∑Bi-M=100-1=99, 100 > 99 true, 100 ≤ 100 true -> YES. But careful: Under nonnegativity, we need to check feasibility: B1=100 => A1 ∈ (99,100] (since ceil(A1)=100 => A1 ∈ (99,100] ; because if A1=100 exactly, ceil=100; if A1=99.5, ceil=100). B2=0 => A2=0. Sum must be 100. Can we find A1 in (99,100] such that A1 + 0 = 100? That requires A1=100 exactly. A1=100 is allowed (since 100 is integer and ceil(100)=100). So solution exists. So both say YES.
Now B=[101, -?] we saw yields NO in both? Actually B=[101,0] unrestricted: ∑Bi-N=101-2=99, 100 > 99 true, 100 ≤ 101 true => YES (since we found solution A1=100.5, A2=-0.5). So unrestricted says YES, nonneg says NO. So the difference appears when there is a zero and a large B_i. Which answer would problem expect? The problem is from CodeChef (maybe). I recall a problem called "Sereja and Voting" or something. I'm trying to recall known results. There is a CodeChef problem "SEAVOTE" maybe? Actually there is a known problem: "Sereja and Votes" or "Correctness of Knight Move"? Not sure. Let's search memory: There's a CodeChef problem "SEAVOTE" about percentages rounding up. I think the known solution is the condition sum(B) - N < 100 <= sum(B). Many editorial solutions use that. And they usually treat Ai can be any real numbers, not necessarily nonnegative. Because they often mention that negative percentages can be allowed as a trick? But they might not care. Actually in "SEAVOTE", the problem is about checking if given percentages after rounding up could sum to 100. I recall a problem "SEAVOTE" on CodeChef where the condition is exactly that. But I'm not entirely sure.
Let's try to find if there's any known constraints: The problem statement here says "Ai percent of people voted for opinion number i." That suggests Ai are percentages, so they should be between 0 and 100. In real life, percentages are between 0 and 100. However, in many programming contest problems, they consider percentages as numbers that sum to 100, but they don't restrict them to be between 0 and 100, sometimes they allow over 100 if there is a mistake? But it's weird.
But the test case 2: 25 25 25 25 works because all are exactly 25. Test case 3: 50 51 works with 49.5 and 50.5, both nonnegative and within 0-100. So all test cases have nonnegative solutions.
Maybe there is a hidden condition: "Ai percent of people voted for opinion number i." Usually percent implies between 0 and 100, but not explicitly stated. Many problems explicitly say 0 <= Ai <= 100. Here they didn't. They also didn't say "Ai is a real number" but it's implied. They also gave Bi up to 1000, which is beyond 100, so they probably consider cases where Bi > 100, which would require some Ai > 100 if nonnegative, making sum >100 impossible. But they might still consider those cases and answer NO. But the condition sum(B) - N < 100 <= sum(B) would sometimes say YES for such cases if there is a zero, but that solution would require negative Ai. So which answer is correct according to problem's intention? Let's see if there is any known problem with this exact wording. Searching memory: There is a problem "Sereja and Voting" from CodeChef (maybe SEAVOTE). Actually I recall a problem called "SEAVOTE" where you have to determine if given rounded percentages could sum to 100. The condition is sum - N < 100 <= sum. But I'm not entirely sure. Let's think about typical puzzles: You have percentages that are rounded up to nearest integer (or maybe rounded normally). The condition for existence of original percentages summing to 100 given rounded up percentages is that sum of rounded values is at least 100 and less than 100+N. Actually if you round up, each original is at most its rounded value and more than rounded value minus 1. So total original sum is > sum(rounded) - N and <= sum(rounded). So to be able to achieve exactly 100, we need 100 to be in that interval (strict > left, <= right). That is exactly sum(rounded) - N < 100 <= sum(rounded). That is a known condition. And negative percentages are not considered because original percentages are between 0 and 100? Actually if you allow negative, the lower bound is sum(rounded)-N, but if some rounded are zero, you could go below zero? The lower bound is sum(rounded)-N. But if you restrict percentages to be nonnegative, then also each original must be >=0, which imposes additional constraints: for each i with rounded value 0, original must be exactly 0. That changes the lower bound: effectively sum_{rounded>0} (rounded_i - 1) is the lower bound, which is sum(rounded) - (number of positive values). So the condition becomes sum(rounded) - countPositive < 100 <= sum(rounded). That is also a known condition when you require nonnegative percentages.
Which one is more common? I've seen problems like "Given rounded percentages (rounded up), is it possible that the original percentages sum to 100?" Usually they assume percentages are nonnegative. But if they assume nonnegative, they'd have to count positive B_i. However, the known simple condition sum(B) - N < 100 <= sum(B) appears often. Let's search my memory: There's a Codeforces problem "Little Pony and Sort by Shift"? No. There's an AtCoder problem? Actually I recall a problem "SEAVOTE" (Sereja and Vote) maybe. Let's google in my mind: There is CodeChef problem "SEAVOTE" where the input is sum of Bi? Not sure.
But this problem mentions Sereja, a common character in CodeChef problems. So it's likely a CodeChef problem. I'll try to recall: There's a problem "Sereja and Votes" (code: SEAVOTE). I think I've seen editorial: The condition is that if sum of B_i is less than 100 or greater than 100+N-1? Something like that. Actually if each A_i is rounded to nearest integer? But here it's rounding up.
Let's derive properly:
We have: ceil(A_i) = B_i. So A_i ∈ (B_i-1, B_i] for all i. If we also require A_i >= 0, then for B_i = 0, we must have A_i ∈ [0,0] i.e., A_i=0. So effectively for B_i=0, the interval reduces to a point.
Thus overall possible sum range is from L to U, where:
U = ∑ B_i (attained).
L = ∑{i: B_i > 0} (B_i - 1) + ∑{i: B_i = 0} 0 = ∑ B_i - M, where M = number of B_i > 0. But note that L is not attainable because for each B_i > 0, the lower bound is open (strict). However, if there is any B_i > 0, we can approach L arbitrarily close but not reach it. If M = 0 (all B_i=0), then L=0, but sum must be 100, impossible. So generally L is a lower bound not inclusive.
Thus condition for existence is: 100 > ∑ B_i - M and 100 ≤ ∑ B_i. That is: ∑ B_i - M < 100 ≤ ∑ B_i.
Now consider the condition without nonnegativity: L' = ∑ (B_i - 1) = ∑ B_i - N, and condition is ∑ B_i - N < 100 ≤ ∑ B_i.
So the difference is that the left side is stronger when there are zeros; zeros effectively increase the left bound because they contribute -1 in the unrestricted case but 0 in the restricted case. So the condition is more restrictive (i.e., makes it harder to achieve 100) when there are zeros.
Which one did the problem test? They gave examples: 3: 30 30 30 -> sum=90, N=3, sum-N=87, condition says 87<100≤90? 100≤90 false -> NO. Works for both because M=3 (all positive), so sum-M=87 as well. So both same.
Example 2: 25 25 25 25 -> sum=100, N=4, sum-N=96, 100>96 true, 100≤100 true -> YES. M=4, sum-M=96 -> same.
Example 3: 50 51 -> sum=101, N=2, sum-N=99, 100>99 true, 100≤101 true -> YES. M=2, sum-M=99 -> same.
Thus all given examples have M = N (all B_i > 0). So they don't test cases with zeros. So we cannot deduce which condition they intended.
We need to see if there is any official editorial or known solution. Since it's from a contest, likely the intended solution is the simpler condition sum - N < 100 <= sum. Many participants would derive that. The nonnegativity nuance might be overlooked, but problem setter might have missed it as well. Usually in such problems, they don't require Ai to be nonnegative unless explicitly stated. However, the phrase "percent" implies nonnegative. But many contest problems use the term "percent" loosely to mean proportion out of 100, not necessarily between 0 and 100? Actually percent means per hundred, so it's a number out of 100. It can be more than 100? Usually not; it's typically between 0 and 100, but there is concept of "percentage points" exceeding 100? In voting, percentages sum to 100, each between 0 and 100. So I'd say nonnegativity and <=100 are natural. But the problem also says "Ai percent of people voted for opinion number i." So if Ai > 100, that would mean more than 100% voted for that opinion, impossible if others are nonnegative. So they'd be forced to be ≤100. But they didn't state that explicitly. However, they allowed Bi up to 1000. So Bi could be >100, which would imply Ai >100, impossible if sum=100 and others nonnegative. So they'd have to answer NO for such cases. The condition sum - N < 100 <= sum would sometimes say YES for Bi>100 with zeros, but that would require negative Ai for zeros, which would be negative percentages, also impossible. So the condition sum - N < 100 <= sum would incorrectly say YES for cases that should be NO if we respect nonnegativity. But maybe the problem does not require nonnegativity; they just treat Ai as any real numbers. In that case, negative percentages are allowed, which is weird but mathematically okay. However, the problem statement says "percent", which typically is nonnegative. But many contest problems ignore that nuance and just treat them as real numbers. They may not have considered the possibility of negative values, but they'd still be covered by the math. The test cases they provided don't include zeros, so both conditions yield same results. But they might have included zeros in hidden test cases. We need to see if the problem expects us to account for nonnegativity.
Let's try to search online memory: I recall a CodeChef problem called "Sereja and Votes" (code: SEAVOTE). I think the problem goes: Given the rounded percentages (rounded up), determine if original percentages summing to 100 could exist. The editorial says condition: 100 > sum - n and 100 <= sum. However, I'm not entirely sure. Let me recall: There is a known CodeChef problem "CORRCHK" or something. Actually I'll try to recall the exact problem. I think it's from CodeChef January Challenge maybe? I'm not sure.
Alternatively, let's think about typical rounding problems: There's also the "rounding error" problem from Google Code Jam, where percentages are rounded to nearest integer using specific rounding rule. But here it's rounding up.
Another angle: They define "rounded up" as: if Ai is not integer, round up to next integer; otherwise leave as is. That's exactly ceil. And they ask whether there exists some valid statistic A such that after rounding it up, it becomes same as B. The statistic A is "valid if sum of all Ai is equal to 100." They don't mention any other restrictions like 0 <= Ai <= 100. So it's plausible they treat Ai as any real numbers. The term "percent" might be misused; maybe they just mean "the proportion multiplied by 100", so it can be any real number, but in typical usage percentages are between 0 and 100, but the problem might ignore that.
Consider the sample: third case has 50 51. The original A is 49.5 and 50.5, both within 0-100. That's fine. So both conditions work.
But consider a case like B = [0, 100]. Both conditions give YES? Let's compute: sum=100, N=2, sum-N=98, condition: 100 > 98 and 100 ≤ 100 -> YES (unrestricted). Nonneg: M=1, sum-M=99, 100>99 and 100≤100 -> YES. So both say YES. With nonneg, we need A1=0, A2=100. That works. So both say YES.
Now B = [0, 101] as we saw: unrestricted says YES, nonneg says NO. Which answer is more sensible? If we think as percentages, can we have a statistic where one opinion gets 101% after rounding up? That would require original >100, which can't happen because total is 100 and others are nonnegative. So it should be impossible. So answer should be NO. That suggests nonnegativity is needed.
But could there be a solution with A1= -0.5, A2=100.5? That gives percentages -0.5% and 100.5%. Negative percentage is nonsensical. So likely they intend nonnegative. However, the problem statement didn't explicitly forbid negative values, but it says "Ai percent of people voted". That implies Ai is a percentage, so should be between 0 and 100. In many programming problems, they treat percentages as numbers between 0 and 100, but they sometimes allow numbers >100 if the sum of percentages is 100? Actually if one is >100, sum can't be 100 with others nonnegative. So that would be impossible. So they'd probably want to reject such cases. So the nonnegativity condition seems natural.
But then what about Bi > 100? The problem constraints allow Bi up to 1000. So they likely expect that we need to reject cases where any Bi > 100? Not necessarily; there could be multiple Bi > 100? But any Bi > 100 automatically forces sum of A > 100 if all Ai >=0, because that Ai > 100, others >=0, sum >100, contradict sum=100. So any Bi > 100 would make it impossible. But does our condition with nonnegativity automatically reject those? Let's test: If any Bi > 100, then consider the condition sum - M < 100 <= sum. Since sum includes that Bi, sum > 100? Possibly but could be exactly 100? No, Bi > 100, so sum >= Bi > 100, so 100 <= sum could be true. But also need sum - M < 100. That could be true or false. For B=[101,0] we had sum=101, M=1, sum-M=100, not < 100 (equal), so condition fails. For B=[102,1]? sum=103, M=2, sum-M=101, 100 > 101? false. So fails. But what about B=[150, -? can't have negative]. To have sum - M < 100, we need sum - M < 100. If Bi > 100 and there are some other positive numbers, sum is large, sum-M might still be >=100. If Bi is just above 100 and there are many zeros, sum-M = (Bi + zeros) - (maybe 1 if only Bi>0) = Bi - 1. For Bi=101, Bi-1=100, not <100. For Bi=102, 101 <100? false. So if there's a single Bi>100 and all others zero, condition fails because sum-M = Bi - 1 >= 100? For Bi=101, 100 not <100; for Bi>101, >100. So fails. But what if there are multiple Bi>100? Then sum-M = sum of all Bi minus count of positives. Since each Bi > 100, sum of all Bi > 100 * M, so sum-M > 100M - M = 99M. For M>=2, 99M >= 198, >100. So fails. So indeed any Bi > 100 will cause condition to fail. But wait, could there be a scenario where Bi > 100 but sum-M < 100? Suppose Bi=101 and there is a negative contribution? But B_i are nonnegative. So sum-M = sum - M. Since each Bi is at most? Actually if Bi=101 and others are zeros, M=1, sum-M=100, not <100. So fails. If Bi=100.5? But B_i integer. So yes, any integer >100 yields Bi-1 >=100. So condition fails. So nonnegativity condition automatically rejects any Bi > 100. That's consistent with intuition.
But the unrestricted condition could accept some cases with Bi>100 if there are zeros, because sum - N could be less than 100. For B=[101,0], sum-N=99, condition says YES. So if they intended nonnegative, they'd have to reject that. Since the problem constraints allow Bi up to 1000, they likely included such cases and expect NO for some like [101,0]. So which is more plausible? Hard to say.
Let's examine more edge cases: B = [0,0,...,0,100] with many zeros: N=100, B_100=100, others 0. Sum=100, N=100, sum-N=0, condition unrestricted: 0 < 100 <= 100 => YES. Nonneg: M=1, sum-M=99, 99 < 100 <= 100 => YES. Both say YES. That works.
B = [0,0,...,0,99] with N=100? Sum=99, sum-N=-1, unrestricted: -1 < 100 <= 99? 100 <= 99 false => NO. Nonneg: M=1, sum-M=98, 98 < 100 <= 99? 100 <= 99 false => NO. So both NO.
B = [0,0,...,0,101] with N=100: sum=101, sum-N=1, unrestricted: 1 < 100 <= 101? yes -> YES. Nonneg: M=1, sum-M=100, 100 < 100? false -> NO. So difference.
Which answer is more logical? If we have one opinion with 101% after rounding, and 99 other opinions with 0% after rounding, can we find original percentages summing to 100? With nonnegativity: The opinion with 101% must have original >100 (since ceil >100 implies >100), so at least >100. Even if it's just 100.0001? Ceil(100.0001)=101? No, ceil(100.0001)=101? Wait, ceil(100.0001) = 101? Actually ceil(100.0001) = 101? No, ceil of a number is the smallest integer >= that number. For 100.0001, the smallest integer >= it is 101? That's not correct: ceil(100.0001) = 101? Let's check: 100.0001 is between 100 and 101. The smallest integer >= 100.0001 is 101? No, 101 is > 100.0001, but 100 is less, but ceil is the next integer greater than or equal to the number. The integers are ... 100, 101, 102... 100 is less than 100.0001, so not >=. 101 is >= 100.0001, so ceil(100.0001)=101. Yes, that's correct: ceil(100.0001) = 101 because 101 is the next integer. So any number greater than 100 and less than or equal to 101 rounds up to 101. So original for 101 must be in (100,101]. So it must be >100. So even the smallest possible is just above 100. So its minimum is >100. Sum of all percentages would be >100 + 0 = >100, so cannot be exactly 100. So indeed impossible. So answer should be NO. So the nonnegativity condition gives NO. The unrestricted condition gave YES because it allowed negative percentages for zeros: we could set the 101's original to 100.0001 (just over 100) and then set one of the zeros to a negative value to bring sum down to 100. For example, A1 (for B=101) = 100.5, and for one of the zeros, set A2 = -0.5. But negative percentage is not plausible. So the problem likely expects NO for such case.
Thus, I'm leaning that the intended solution includes the nonnegativity constraint. But wait, could there be a scenario where negative percentages are considered valid? Usually in voting percentages, they are nonnegative. The problem statement says "Ai percent of people voted for opinion number i." This implies Ai is a percentage, which is between 0 and 100 inclusive. So I'd think they assume Ai >= 0.
But then why would they allow Bi up to 1000? Possibly to test that condition: if any Bi > 100, it's automatically impossible because then sum of Ai would exceed 100. But the condition sum - M < 100 <= sum might already handle that. For B=[101,0], M=1, sum-M=100, condition fails because 100 is not < 100. So it would be NO. So it's okay. However, there could be cases with Bi > 100 but still sum - M < 100? Let's test B=[101, 0, 0] but also some other positive to reduce? Actually M counts positive entries. If there is a Bi=101 and also some other positive, sum increases, and sum-M will be even larger. For B=[101, 1], sum=102, M=2, sum-M=100, still not <100. For B=[102, -?]. For B=102 and 0, sum-M=101, >100. So any Bi>100 yields Bi-1 >=100. Since M includes that Bi, sum-M >= (Bi-1) + sum of other (Bj - 1 for Bj>0). For any Bj >=0, Bj-1 may be negative if Bj=0? But zeros are not counted in M. For zeros, they contribute 0 to sum-M. So sum-M = (Bi - 1) + sum_{other positive} (Bj - 1). For any positive Bj, Bj-1 >= 0 (since Bj >=1). So sum-M >= Bi - 1 >= 100. So sum-M >=