#C11065. Compressed Sequence Problem
Compressed Sequence Problem
Compressed Sequence Problem
You are given a sequence of n integers and an integer k representing the length of each consecutive subsequence. Your task is to compress the sequence by dividing it into chunks of length k and then computing the average of each chunk using integer division. For each chunk, output two numbers: the average value and the value k
(the size of the chunk).
More formally, if a subsequence contains elements \( S_1, S_2, \dots, S_k \), then its average is computed as \[ \text{avg} = \left\lfloor \frac{S_1 + S_2 + \cdots + S_k}{k} \right\rfloor, \] where \(\lfloor x \rfloor\) represents the floor function (i.e., integer division).
The final compressed sequence is the concatenation of these pairs for each subsequence. It is guaranteed that n
is a multiple of k
.
inputFormat
The input is given in two lines. The first line contains two integers n
and k
, where n
is the total number of elements in the sequence and k
is the subsequence length. The second line contains n
space-separated integers representing the sequence.
outputFormat
Output a single line with the compressed sequence. The output should consist of n
space-separated integers (each pair representing the average value of a group and the number k
), computed as described.
8 2
10 20 30 40 50 60 70 80
15 2 35 2 55 2 75 2