博客
关于我
B. Polycarp's Practice
阅读量:598 次
发布时间:2019-03-09

本文共 3621 字,大约阅读时间需要 12 分钟。

B. Polycarp's Practice

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

 

 

Polycarp is practicing his problem solving skill. He has a list of n problems with difficulties a1,a2,…,an, respectively. His plan is to practice for exactly k days. Each day he has to solve at least one problem from his list. Polycarp solves the problems in the order they are given in his list, he cannot skip any problem from his list. He has to solve all n problems in exactly k

days.

Thus, each day Polycarp solves a contiguous sequence of (consecutive) problems from the start of the list. He can't skip problems or solve them multiple times. As a result, in k

days he will solve all the n

problems.

The profit of the j

-th day of Polycarp's practice is the maximum among all the difficulties of problems Polycarp solves during the j-th day (i.e. if he solves problems with indices from l to r during a day, then the profit of the day is maxl≤i≤rai). The total profit of his practice is the sum of the profits over all k

days of his practice.

You want to help Polycarp to get the maximum possible total profit over all valid ways to solve problems. Your task is to distribute all n

problems between k

days satisfying the conditions above in such a way, that the total profit is maximum.

For example, if n=8,k=3

and a=[5,4,2,6,5,1,9,2], one of the possible distributions with maximum total profit is: [5,4,2],[6,5],[1,9,2]. Here the total profit equals 5+6+9=20

.

Input

The first line of the input contains two integers n

and k (1≤k≤n≤2000

) — the number of problems and the number of days, respectively.

The second line of the input contains n

integers a1,a2,…,an (1≤ai≤2000

) — difficulties of problems in Polycarp's list, in the order they are placed in the list (i.e. in the order Polycarp will solve them).

Output

In the first line of the output print the maximum possible total profit.

In the second line print exactly k

positive integers t1,t2,…,tk (t1+t2+⋯+tk must equal n), where tj means the number of problems Polycarp will solve during the j

-th day in order to achieve the maximum possible total profit of his practice.

If there are many possible answers, you may print any of them.

Examples

Input

8 35 4 2 6 5 1 9 2

Output

20

3 2 3

Input

5 11 1 1 1 1

Output

15

Input

 

4 21 2000 2000 2

Output

 

40002 2

Note

The first example is described in the problem statement.

In the second example there is only one possible distribution.

In the third example the best answer is to distribute problems in the following way: [1,2000],[2000,2]

. The total profit of this distribution is 2000+2000=4000.

 

 先把数据存在一个数组啊a[]里,再赋值给b数组,然后把b排序,找出最大的k个数

加起来就是输出的和

再在a里找这几个最大的数

记录下它的位置,然后后一个的位置减去前一个的位置就是那段长度

要注意的是第一个值和最后一个值的位置输出的时候要特殊考虑下就行

 

#include 
using namespace std;#define ll long longint main(){ int n,k,a[2009],b[2009]; int sum; while(scanf("%d%d",&n,&k)!=EOF) { sum=0; int t=0; int ss=0; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); for(int i=0; i
>b[i]; a[i]=b[i]; } sort(a,a+n); for(int i=n-1;; i--) { if(i==n-1-k) break; sum+=a[i]; } cout<
<
n-1-k; j--) { if(b[i]==a[j]) { t++; a[j]=-1; if(t>1) { cout<
<<" "; ss=i; } break; } } } cout<
<

 

转载地址:http://wbhpz.baihongyu.com/

你可能感兴趣的文章
mysql 快速自增假数据, 新增假数据,mysql自增假数据
查看>>
MySql 手动执行主从备份
查看>>
Mysql 批量修改四种方式效率对比(一)
查看>>
mysql 批量插入
查看>>
Mysql 报错 Field 'id' doesn't have a default value
查看>>
MySQL 报错:Duplicate entry 'xxx' for key 'UNIQ_XXXX'
查看>>
Mysql 拼接多个字段作为查询条件查询方法
查看>>
mysql 排序id_mysql如何按特定id排序
查看>>
Mysql 提示:Communication link failure
查看>>
mysql 插入是否成功_PDO mysql:如何知道插入是否成功
查看>>
Mysql 数据库InnoDB存储引擎中主要组件的刷新清理条件:脏页、RedoLog重做日志、Insert Buffer或ChangeBuffer、Undo Log
查看>>
mysql 数据库中 count(*),count(1),count(列名)区别和效率问题
查看>>
mysql 数据库备份及ibdata1的瘦身
查看>>
MySQL 数据库备份种类以及常用备份工具汇总
查看>>
mysql 数据库存储引擎怎么选择?快来看看性能测试吧
查看>>
MySQL 数据库操作指南:学习如何使用 Python 进行增删改查操作
查看>>
MySQL 数据库的高可用性分析
查看>>
MySQL 数据库设计总结
查看>>
Mysql 数据库重置ID排序
查看>>
Mysql 数据类型一日期
查看>>