CF958C3.Encryption (hard)

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Heidi is now just one code away from breaking the encryption of the Death Star plans. The screen that should be presenting her with the description of the next code looks almost like the previous one, though who would have thought that the evil Empire engineers would fill this small screen with several million digits! It is just ridiculous to think that anyone would read them all...

Heidi is once again given a sequence AA and two integers kk and pp . She needs to find out what the encryption key SS is.

Let XX be a sequence of integers, and pp a positive integer. We define the score of XX to be the sum of the elements of XX modulo pp .

Heidi is given a sequence AA that consists of NN integers, and also given integers kk and pp . Her goal is to split AA into kk parts such that:

  • Each part contains at least 11 element of AA , and each part consists of contiguous elements of AA .
  • No two parts overlap.
  • The total sum SS of the scores of those parts is minimized (not maximized!).

Output the sum SS , which is the encryption code.

输入格式

The first line of the input contains three space-separated integers NN , kk and pp ( k<=N<=500000k<=N<=500000 , 2<=k<=1002<=k<=100 , 2<=p<=1002<=p<=100 ) – the number of elements in AA , the number of parts AA should be split into, and the modulo for computing scores, respectively.

The second line contains NN space-separated integers that are the elements of AA . Each integer is from the interval [1,1000000][1,1000000] .

输出格式

Output the number SS as described in the problem statement.

输入输出样例

  • 输入#1

    4 3 10
    3 4 7 2
    

    输出#1

    6
    
  • 输入#2

    10 5 12
    16 3 24 13 9 8 7 5 12 12
    

    输出#2

    13
    

说明/提示

In the first example, if the input sequence is split as (3)(3) , (4,7)(4,7) , (2)(2) , the total score would be . It is easy to see that this score is the smallest possible.

In the second example, one possible way to obtain score 1313 is to make the following split: (16,3)(16,3) , (24)(24) , (13)(13) , (9,8)(9,8) , (7,5,12,12)(7,5,12,12) .

首页