#P2072. Contiguous Groups Partitioning with Minimal Danger
Contiguous Groups Partitioning with Minimal Danger
Contiguous Groups Partitioning with Minimal Danger
There are M distinct religions (numbered 1 to M) and N followers (numbered 1 to N). Each follower follows exactly one religion. They are arranged in a given order. You need to partition these N followers into contiguous groups such that in each group the number of distinct religions (called the danger value) does not exceed K. Otherwise, the group becomes infinitely dangerous.
Your task is to determine two values:
- The minimum number of groups into which the followers can be partitioned.
- The minimum possible total danger value (i.e. the sum of the danger values of all groups) among all valid partitions that use the minimum number of groups.
The danger value for a group is defined as the number of distinct religions present in that group.
Note: Groups must consist of contiguous followers in the order given.
The answer should be printed as two integers: the first is the minimum number of groups, and the second is the corresponding minimum total danger value.
inputFormat
The input consists of two lines:
- The first line contains three integers M, N and K separated by spaces, where M is the total number of religions, N is the number of followers, and K is the maximum allowed distinct religions per group.
- The second line contains N integers separated by spaces; the i-th integer indicates the religion ID (between 1 and M) of the i-th follower.
outputFormat
Output two space‐separated integers on a single line: the minimum number of groups required and the minimum total danger value.
sample
3 5 2
1 2 1 3 2
2 4