아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Maximum sum with swaps

시간 제한6초메모리 제한1024 MB

요약
최대 K번의 교환으로 배열을 재배치한 뒤 연속 구간을 골라 합이 최대가 되게 하고, 교환 과정과 구간을 출력한다.
난이도

보통10점 중 7점

유형
그리디, 정렬, 배열
정답자
아직 제출이 없습니다

문제

Given an array of integers A_iA\_i of length NN, 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 KK 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: NN --- the number of elements in the array (1≤N≤100,0001 \le N \le 100\\,000), KK --- the maximum possible number of swaps (0≤K≤100 \le K \le 10). The second line lists the elements of the array A_iA\_i, one by one. All A_iA\_i are integers, no larger than 10910^9 by absolute value. It is guaranteed that there is at least one positive number among A_iA\_i.

출력

The first line of the output file must contain two integers: SS --- the resulting sum of elements in the interval and MM --- the number of swaps performed (0≤M≤K0 \le M \le K).

The following MM lines must describe all swaps in order of their execution. For every jj-th swap print two integers u_ju\_j and v_jv\_j, denoting two positions in the array, whose values are to be swapped (1≤u_j≠v_j≤N1 \le u\_j \neq v\_j \le N). 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: LL being the index of the leftmost position in the array belonging to the interval, and RR being the index of the rightmost position belonging to the interval (1≤L≤R≤N1 \le L \le R \le N).

예제3

  1. 예제 1

    입력
    3 2
    1 2 3
    
    예상 출력
    6 0
    1 3
    
  2. 예제 2

    입력
    3 3
    1 -2 3
    
    예상 출력
    4 2
    1 2
    2 3
    2 3
    
  3. 예제 3

    입력
    3 0
    1 -2 3
    
    예상 출력
    3 0
    3 3