1. Key Claim: Suppose i,i+1,…,i+k−1 are all good, and i+k is bad. Then,
ai+ai+1+⋯+ai+k−1≥0.
2. Proof of Key Claim: We proceed by induction on k.
- Base Case: For k=0, the statement 0≥0 is trivially true.
- Inductive Step: Assume the claim holds for k−1. We need to show it holds for k.
Since i is good, there exists some 1≤ℓ≤m such that
ai+ai+1+⋯+ai+ℓ−1≥0.
We consider two cases:
- Case 1: 1≤ℓ≤k. By the induction hypothesis, we have
ai+ℓ+ai+ℓ+1+⋯+ai+k−1≥0.
Adding these two inequalities, we get
ai+ai+1+⋯+ai+k−1≥0.
- Case 2: ℓ≥k+1. Since i+k is bad, we have
ai+k+ai+k+1+⋯+ai+ℓ−1<0.
Therefore,
ai+ai+1+⋯+ai+k−1≥−(ai+k+ai+k+1+⋯+ai+ℓ−1)>0.
Thus, the claim holds in both cases.
■
3. **Handling the Case ∣T∣<n**: If ∣T∣<n, we can split T into contiguous blocks. By the key claim, the sum of ai over each block is nonnegative. Therefore, the total sum ∑k∈Tak≥0.
4. **Handling the Case ∣T∣=n**: If all indices are good, we use induction on m.
- Base Case: For m=1, every ai≥0, so ∑k∈Tak≥0.
- Inductive Step: Assume the statement holds for m−1. We need to show it holds for m.
Let S be the set of indices that are good but become bad when m is replaced with m−1. We have the following claims:
- Claim 1: If i∈S, then for any j∈[i+1,i+m−1],
aj+aj+1+⋯+ai+m−1≥0.
- Claim 2: If i∈S, there exists some j such that
ai+ai+1+⋯+aj≥0,
and none of i,i+1,…,j are in S.
Proof of Claim 1: This follows from the fact that ai+⋯+aj−1<0 and ai+⋯+ai+m−1≥0.
Proof of Claim 2: Suppose the smallest j such that ai+ai+1+⋯+aj≥0 satisfies ℓ∈S for some ℓ∈[i,j]. Then,
aℓ+⋯+aj<0,
so
ai+⋯+aℓ−1≥0.
We can keep removing elements like this until none of the indices are in S.
Back to the induction: The first part of the claim implies that the intervals [i,i+m−1] are disjoint for i∈S, so the sum of ai for those intervals is nonnegative. The rest of the indices have sums that are nonnegative and do not go into these intervals. Thus, we may delete these intervals, and the problem reduces to the case where all the indices are good with m replaced with m−1. The inductive hypothesis now finishes the proof.
■
The final answer is k∈T∑ak≥0.