3214.Sereja and Swaps

Time Limit: 1s Memory Limit: 256MB

As usual, Sereja has array a, its elements are integers: a[1],a[2],...,a[n]. Let's introduce notation:

3214_1.png

A swap operation is the following sequence of actions:
choose two indexes i,j (i \neq j); perform assignments tmp=a[i],a[i]=a[j],a[j]=tmp.
What maximum value of function m(a) can Sereja get if he is allowed to perform at most k swap operations?

Input Format(From the terminal/stdin)

The first line contains two integers n and k (1 \le n \le 200;1 \le k \le 10). The next line contains n integers a[1], a[2], ..., a[n] (-1000 \le a[i] \le 1000).

Output Format(To the terminal/stdout)

In a single line print the maximum value of m(a) that Sereja can get if he is allowed to perform at most k swap operations.

Sample Input 1

Copy
10 2
10 -1 2 2 2 2 2 2 -1 10
  · \n
  ·  · · · · · · ·  ·  \n

Sample Output 1

Copy
32
  \n

Sample Input 2

Copy
5 10
-1 -1 -1 -1 -1
 ·  \n
  ·  ·  ·  ·  \n

Sample Output 2

Copy
-1
  \n

Submit

请先 登录

© 2025 FAQs