Codeforces Round #243 (Div. 1) A Sereja and Swaps

来源:互联网 发布:手机免费网络电话软件 编辑:程序博客网 时间:2024/06/05 09:11
URL:http://codeforces.com/contest/425/problem/A

题目描述:

                                                        A. Sereja and Swaps
                          time limit per test                                    memory limit per test
                              1 second                                                256 megabytes

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

Codeforces Round 243 (Div. 1) A Sereja and Swaps 解题报告 - wmy0831988 - wmy0831988的博客

A swap operation is the following sequence of actions:

  • choose two indexes i,?j(i?≠?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 mostk swap operations?

Input

The first line contains two integers n andk(1?≤?n?≤?200; 1?≤?k?≤?10). The next line containsn integersa[1],a[2],...,a[n](?-?1000?≤?a[i]?≤?1000).

Output

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

Sample test(s)
Input
10 210 -1 2 2 2 2 2 2 -1 10
Output
32
Input
5 10-1 -1 -1 -1 -1
Output
-1

解题思路:穷举
       穷举所有范围内能取得的最大值,对于某一范围,将此范围内的数据单独拿出并排序,再把此范围外的数据存入另一数组并排序,在k次之内,每次拿后者的最大值a替换前者的最小值b(前提是a>b)。


代码:

0 0
原创粉丝点击