#P15347. [TOIP 2025] 疊加最大值
[TOIP 2025] 疊加最大值
Problem Description
In a positive integer array or subarray, for each distinct number, multiply the number by its number of occurrences; this is called its superposition value. A “subarray” means a part of an array made up of consecutive elements. For example, in the array , the superposition value of is , the superposition value of is , the superposition value of is , and the superposition value of is .
Given a positive integer array of length and a positive integer , this problem asks for the maximum superposition value in every subarray of length . There are subarrays of length in total. Output the sum of these maximum superposition values.
For example, the input array is , with and . The maximum superposition values of each subarray are:
- For , the maximum superposition value is .
- For , the maximum superposition value is .
- For , the maximum superposition value is .
- For , the maximum superposition value is .
The sum of all maximum superposition values is .
Input Format
$$\begin{aligned} &n \; k \\ &c_0 \; c_1 \; \cdots \; c_{n-1} \end{aligned}$$- is the length of the array.
- is the required subarray length.
- is the -th positive integer in the array.
Output Format
- is the sum of all maximum superposition values.
8 5
4 5 2 3 4 2 2 5
24
Hint
Constraints
- .
- .
- .
Scoring
This problem has three subtasks with the following constraints.
Each subtask may contain one or more testdata files. You will get the score for a subtask only if you answer all testdata in that subtask correctly.
| Subtask | Score | Additional Input Constraints |
|---|---|---|
| 1 | 6 | The input satisfies , and . |
| 2 | 38 | The input satisfies that all numbers in the array are pairwise distinct. |
| 3 | 56 | No additional constraints. |
Translated by ChatGPT 5