#P8049. Longest Interesting Subsequence
Longest Interesting Subsequence
Longest Interesting Subsequence
We are given an integer sequence \(A\) of length \(N\) and an integer \(S\). A contiguous subarray of even length \(L=2\times K\) is said to be interesting if both of the following conditions hold:
\(\sum_{i=0}^{K-1} A_i \le S\) and \(\sum_{i=K}^{2K-1} A_i \le S\).
For each starting index of \(A\), you are to output the longest interesting subarray beginning at that index. If no interesting subarray exists starting from a particular index, output an empty line.
inputFormat
The first line contains two integers \(N\) and \(S\). The second line contains \(N\) integers representing the sequence \(A\), separated by spaces.
outputFormat
Output \(N\) lines. The \(i\)-th line should contain the longest interesting subarray starting from the \(i\)-th element of \(A\) (elements separated by a space). Output an empty line if no interesting subarray exists starting from that index.
sample
6 5
1 2 1 1 2 1
1 2
2 1 1 2
1 1
1 2
2 1
1
</p>