Maximum sum with swaps
시간 제한6초메모리 제한1024 MB
최대 K번의 교환으로 배열을 재배치한 뒤 연속 구간을 골라 합이 최대가 되게 하고, 교환 과정과 구간을 출력한다.
문제
Given an array of integers of length , you are to find an interval within the array, which has maximum sum of the elements in it. However, before choosing the interval, you are allowed to perform no more than swaps. Each swap makes two elements of the array exchange places.
An interval within the array is an arbitrary set of its consecutive elements.
입력
The first line of the input file contains two integers: --- the number of elements in the array (), --- the maximum possible number of swaps (). The second line lists the elements of the array , one by one. All are integers, no larger than by absolute value. It is guaranteed that there is at least one positive number among .
출력
The first line of the output file must contain two integers: --- the resulting sum of elements in the interval and --- the number of swaps performed ().
The following lines must describe all swaps in order of their execution. For every -th swap print two integers and , denoting two positions in the array, whose values are to be swapped (). The positions in the array are numbered consecutively starting from one.
The last line must contain the interval where the sum must be calculated, described as two integers: being the index of the leftmost position in the array belonging to the interval, and being the index of the rightmost position belonging to the interval ().