#C1888. Seed Distribution Problem
Seed Distribution Problem
Seed Distribution Problem
Sam is a park ranger tasked with managing the distribution of seeds across several sections of a park. The park is divided into N sections, and each section i requires at least a minimum number of seeds a_i. Sam has a total of S seeds available for distribution.
The goal is to determine whether it is possible to exactly meet the minimum demands. Formally, let \( \text{total\_demand} = \sum_{i=1}^{N} a_i \). If \( \text{total\_demand} < S \), then the distribution is considered "Exact" (i.e. the surplus is acceptable). Otherwise, if \( \text{total\_demand} \ge S \), the answer should be the surplus calculated as \( S - \text{total\_demand} \), which may be zero or negative.
For example, if one test case is given with N=3
, S=100
and the demands [20, 30, 40]
, then the total demand is \(90\) which is less than \(100\), and the output should be "Exact". In another case with N=2
, S=50
and demands [30, 30]
, the total demand is \(60\) so the output is \(50-60=-10\).
inputFormat
The input is read from standard input (stdin) and is structured as follows:
T N1 S1 a1 a2 ... aN1 N2 S2 a1 a2 ... aN2 ... NT ST a1 a2 ... aNT
where T
is the number of test cases. For each test case, the first line contains two integers N
(the number of sections) and S
(the total number of seeds). The following line contains N
integers representing the minimum seed demand for each section.
outputFormat
For each test case, print the answer on a new line. The answer is "Exact" if the total seed demand is strictly less than S
. Otherwise, output the value of \( S - \text{total\_demand} \), where \( \text{total\_demand} = \sum_{i=1}^{N} a_i \).
1
3 100
20 30 40
Exact
</p>