#P2072. 宗教问题

    ID: 2818 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 显示难度普及 上传者: 标签>动态规划 DP线性数据结构

宗教问题

Background

In a region there are many religions. Believers of different faiths often have conflicts. As the person responsible for public security, you need to separate them to prevent escalation.

Problem Description

It is known that there are MM religions (numbered 1M1\sim M) and NN believers (numbered 1N1\sim N), and each believer believes in exactly one religion.

Now you need to split these NN believers, in order, into several groups. The danger value of a group is defined as the number of distinct religions in that group, and a group may not contain more than KK religions; otherwise it is infinitely dangerous.

Problem:

  1. Into how many groups at least must these NN believers be divided?
  2. What is the minimum possible sum of the danger values of these groups?

Input Format

The first line contains three positive integers N,M,KN,M,K, separated by spaces.

The second line contains NN positive integers, the religion number of each believer.

Output Format

The first line contains one positive integer, the minimum number of groups.

The second line contains one positive integer, the minimum total danger value.

10 4 3
1 2 3 4 3 4 3 2 1 2

3
6

Hint

Sample explanation:

One optimal partition is:

[1,2,3]  /  [4,3,4,3,2]  /  [1,2][1,2,3]\ \ /\ \ [4,3,4,3,2]\ \ /\ \ [1,2]

Constraints:

For 20%20\% of the testdata, N20N \le 20.

For 50%50\% of the testdata, N100N \le 100.

For 100%100\% of the testdata, 1N10001 \le N \le 1000, 1K<M201 \le K < M \le 20.

Translated by ChatGPT 5