NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

# 连续子段和

## 题目背景

评测时默认开启 O2 优化

序列 $a_1, a_2, ldots, a_N$ 的最大子段和是指

$$ max_{1 le l le r le N} { sum_{i=l}^{r} a_i}$$

## 题目描述

给定一个长度为 $N$ 的整数序列 $a_1, a_2, ldots, a_N$。

每次操作,你可以交换序列中的任意两个整数 $a_i, a_j$ ($i ne j$)的位置。

假设你的操作次数**不能超过** $M$。请问对于一个完成操作(操作次数也可以为 $0$)的序列而言,其中的最大子段和是多少。

## 输入格式

第一行两个整数 $N, M$,表示序列长度与操作次数上限。

第二行 $N$ 个整数 $a_1, a_2, ldots, a_N$,依次描述序列的每一个元素。

## 输出格式

一个整数,表示你的答案。

## 样例 #1

### 样例输入 #1

```
10 2
10 -1 2 2 2 2 2 2 -1 10
```

### 样例输出 #1

```
32
```

## 样例 #2

### 样例输入 #2

```
5 10
-1 -1 -1 -1 -1
```

### 样例输出 #2

```
-1
```

## 提示

本题共 $7$ 个子任务,每个子任务捆绑计分:

- 子任务#$1$,$10$分,$N = 2000$,$M = 0$
- 子任务#$2$,$10$分,$N = 100$,$M = 1$
- 子任务#$3$,$15$分,$N = 500$,$M = 1$
- 子任务#$4$,$15$分,$N = 50$,$M = 2$
- 子任务#$5$,$15$分,$N = 300$,$M = 10$
- 子任务#$6$,$10$分,$N = 600$,$M = 20$
- 子任务#$7$,$25$分,$N = 2000$,$M = 100$

对于全部测试数据,满足 $|a_i| le 10^4$。
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.