Codeforces 1006B Polycarp's Practice

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 kdays.

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 kdays he will solve all the nproblems.

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 nproblems 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 kpositive 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 3
5 4 2 6 5 1 9 2

Output

20
3 2 3

Input

5 1
1 1 1 1 1

Output

1
5

Input

4 2
1 2000 2000 2

Output

4000
2 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

.

题意:这个人有n个问题,想在m天内把这n个问题都解决了,每一个问题都有一个困难值。第一天从第一个问题开始解决,然后你不能跳过问题,先把第A个问题放一下,然后先解决第A+1个问题。每一天的最大收益为当天解决的问题中最大的困难值。然后题目让我们求这k天最大的收益和 还有每一天的解决问题数量,如果答案不唯一的话,输出其中一个就行。

解题思路:我想要k天的收益和最大,那么我保证每一天的收益最大就行,那么在2e3个数里找最大的那几个就行了,我再把他们所在的位置标记一下,然后再暴力跑一遍数组就ok了。

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn=2e3+10;
int n,m,vis[maxn];
struct Node{
	int sum,pos;
}node[maxn];
bool cmp(Node a,Node b){
	if(a.sum==b.sum) return a.pos<b.pos;
	return a.sum>b.sum;
}
int main(){
	int i,j;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++){
		scanf("%d",&node[i].sum);
		node[i].pos=i;
	}
	sort(node+1,node+n+1,cmp);
	memset(vis,0,sizeof(vis));
	int ans=0;
	for(i=1;i<=m;i++){
		ans+=node[i].sum;
		vis[node[i].pos]=1;
	}
	printf("%d\n",ans);
	int t=0,te=1;
	for(i=1;i<=n;i++){
		if(!vis[i]) t++;
		else{
			if(te<m){
				printf("%d ",t+1);
				t=0;
				te++;
			}
			else t++;
		}
	}
	printf("%d\n",t);
	return 0;
} 

猜你喜欢

转载自blog.csdn.net/bao___zi/article/details/81169695