Company: D. E. Shaw
Difficulty: medium
Longest Subsequence Under an Index-Weighted Sum For a subsequence chosen at one-based indices `i1 < i2 < ... < ik`, define its index-weighted sum as `sum(i_j * k + a[i_j])`. Given a positive integer array and `max_sum`, output the largest possible subsequence length with weighted sum at most `max_sum`. Input Format The first line contains `n` and `max_sum`. The second line contains `n` positive integers. Output Format Print the largest valid length. Constraints `1 <= n <= 200000`, `1 <= a[i] <= 10000`, and `1 <= max_sum <= 10^15`. Example For `n = 4`, `a = [4, 3, 2, 1]`, and `max_sum = 33`, the answer is `3`: choosing indices `1, 2, 4` gives `3*1+4 + 3*2+3 + 3*4+1 = 29`.