#K67862. Compress Memory Usage Log
Compress Memory Usage Log
Compress Memory Usage Log
Given an array of memory usage logs over N intervals and a threshold T, your task is to compress the log by retaining only those entries where the change in memory usage is significant. Specifically, the first entry is always kept, and for each subsequent entry M[i], if the absolute difference from the last kept entry is at least T
(i.e., \(|M[i] - M[j]| \ge T\) where \(M[j]\) is the last recorded log), then M[i] is appended to the compressed log.
Input Example:
5 10 100 115 120 105 130
Output Example:
100 115 105 130
Implement the solution such that it reads from stdin
and writes the result to stdout
.
inputFormat
The first line contains two integers N and T where:
- N (\(1 \leq N \leq 10^5\)) is the number of memory usage intervals.
- T (\(0 \leq T \leq 10^9\)) is the threshold defining a significant change.
The second line contains N space-separated integers representing the memory usage log (\(M_0, M_1, \dots, M_{N-1}\)).
outputFormat
Output a single line containing the compressed log as space-separated integers. The log always starts with the first memory entry and only includes subsequent entries that differ from the last kept value by at least T
.
5 10
100 100 100 100 100
100