Bad Triangle

From Codeforces 1398A. A non-decreasing array nums of n positive integers is given. Decide whether some triple of indices i < j < k fails the non-degenerate triangle inequality, that is whether nums[i] + nums[j] <= nums[k].

The runner compares one canonical witness, so the return value is:

  • 1002000 + n when a bad triangle exists. This encodes the 1-based indices (1, 2, n) as 1 * 10^6 + 2 * 10^3 + n.
  • -1 when every triple forms a valid triangle.
Examples
Input: [1,2,3]
Output: 1002003
Hints

Bad Triangle

**From Codeforces 1398A.** A non-decreasing array `nums` of `n` positive integers is given. Decide whether some triple of indices `i < j < k` fails the non-degenerate triangle inequality, that is whether `nums[i] + nums[j] <= nums[k]`.