Approach hintTry it first, then revealHide
Build one prefix-sum array over the original costs and another over a sorted copy; the query type selects the array. Sums exceed 32 bits, so use long long.
Build one prefix-sum array over the original costs and another over a sorted copy; the query type selects the array. Sums exceed 32 bits, so use long long.