CF958C2.Encryption (medium)

普及+/提高

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Heidi has now broken the first level of encryption of the Death Star plans, and is staring at the screen presenting her with the description of the next code she has to enter. It looks surprisingly similar to the first one – seems like the Empire engineers were quite lazy...

Heidi is once again given a sequence A, but now she is also given two integers k and p. She needs to find out what the encryption key S is.

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

Heidi is given a sequence A that consists of N integers, and also given integers k and p. Her goal is to split A into k part such that:

  • Each part contains at least 1 element of A, and each part consists of contiguous elements of A.
  • No two parts overlap.
  • The total sum S of the scores of those parts is maximized.

Output the sum S – the encryption code.

海蒂已经成功破解了死星设计图的第一层加密,此刻正盯着屏幕,屏幕上显示着她需要输入的下一段密码的描述。这段密码看起来与第一段惊人地相似——看来帝国的工程师们相当懒惰……

海蒂再次获得了一个序列 AA,但这次她还额外获得了两个整数 kk 和 pp。她需要据此找出加密密钥 SS。

设 XX 是一个整数序列,pp 为一个正整数。我们定义 XX 的得分为 XX 中所有元素之和对 pp 取模的结果,即 (∑x∈Xx) mod p\left(\sum_{x \in X} x\right) \bmod p。

海蒂获得了一个由 NN 个整数组成的序列 AA,以及整数 kk 和 pp。她的目标是将 AA 划分为 恰好 kk 个部分,满足:

  • 每一部分至少包含 AA 中的一个元素,且每一部分均由 AA 中连续的元素构成;
  • 各部分之间互不重叠;
  • 这 kk 个部分的得分之和 SS 达到最大值。

请输出该最大和 SS —— 即加密密钥。

输入格式

The first line of the input contains three space-separated integer N, k and p (k ≤ N ≤ 20 000, 2 ≤ k ≤ 50, 2 ≤ p ≤ 100) – the number of elements in A, the number of parts A should be split into, and the modulo for computing scores, respectively.

The second line contains N space-separated integers that are the elements of A. Each integer is from the interval [1, 1 000 000].

输入的第一行包含三个用空格分隔的整数 NN、kk 和 pp(满足 k ≤ N ≤ 20 000k ≤ N ≤ 20\,000,2 ≤ k ≤ 502 ≤ k ≤ 50,2 ≤ p ≤ 1002 ≤ p ≤ 100),分别表示数组 AA 的元素个数、需将 AA 划分的段数,以及计算得分时所用的模数。

第二行包含 NN 个用空格分隔的整数,即数组 AA 的元素。每个整数均在区间 [1, 1 000 000][1,\,1\,000\,000] 内。

输出格式

Output the number S as described in the problem statement.

输出问题描述中所述的数 S。

输入输出样例

  • 输入#1

    4 3 10
    3 4 7 2

    输出#1

    16
  • 输入#2

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

    输出#2

    37

说明/提示

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

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

在第一个例子中,如果输入序列被划分为 (3, 4)(3,\,4)、(7)(7)、(2)(2),则总得分为 。显然,该得分是最大值。

在第二个例子中,一种可获得得分 3737 的划分方式为:(16, 3, 24)(16,\,3,\,24)、(13, 9)(13,\,9)、(8)(8)、(7)(7)、(5, 12, 12)(5,\,12,\,12)。

输入解题思路,AI测评打分。不知道怎么写?

首页