CF1006B.Polycarp's Practice

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Polycarp is practicing his problem solving skill. He has a list of nn problems with difficulties a1,a2,,ana_1, a_2, \dots, a_n , respectively. His plan is to practice for exactly kk 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 nn problems in exactly kk 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 kk days he will solve all the nn problems.

The profit of the jj -th day of Polycarp's practice is the maximum among all the difficulties of problems Polycarp solves during the jj -th day (i.e. if he solves problems with indices from ll to rr during a day, then the profit of the day is maxlirai\max\limits_{l \le i \le r}a_i ). The total profit of his practice is the sum of the profits over all kk 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 nn problems between kk days satisfying the conditions above in such a way, that the total profit is maximum.

For example, if n=8,k=3n = 8, k = 3 and a=[5,4,2,6,5,1,9,2]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][5, 4, 2], [6, 5], [1, 9, 2] . Here the total profit equals 5+6+9=205 + 6 + 9 = 20 .

输入格式

The first line of the input contains two integers nn and kk ( 1kn20001 \le k \le n \le 2000 ) — the number of problems and the number of days, respectively.

The second line of the input contains nn integers a1,a2,,ana_1, a_2, \dots, a_n ( 1ai20001 \le a_i \le 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).

输出格式

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

In the second line print exactly kk positive integers t1,t2,,tkt_1, t_2, \dots, t_k ( t1+t2++tkt_1 + t_2 + \dots + t_k must equal nn ), where tjt_j means the number of problems Polycarp will solve during the jj -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.

输入输出样例

  • 输入#1

    8 3
    5 4 2 6 5 1 9 2
    

    输出#1

    20
    3 2 3
  • 输入#2

    5 1
    1 1 1 1 1
    

    输出#2

    1
    5
    
  • 输入#3

    4 2
    1 2000 2000 2
    

    输出#3

    4000
    2 2
    

说明/提示

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][1, 2000], [2000, 2] . The total profit of this distribution is 2000+2000=40002000 + 2000 = 4000 .

首页