Minimize altered quantities so a compressed array fits within I bytes.
Quantities at checkpoints are stored in an array of size n. Each unique quantity requires k bits, where k is the smallest integer >= log2(number of unique quantities), so total storage is n * k bits. To compress, choose a range x <= y: quantities greater than y become y, quantities less than x become x, quantities within [x, y] are unchanged. Compress so the data fits within I bytes while minimizing the number of altered quantities.
Input: first line n and I (available storage in bytes); second line n space-separated integers. Output: a single integer, the minimum number of quantities that must be altered.
Sample 1: '6 2' / '2 1 2 3 4 3' -> 0 (4 unique values, k = 2, 12 bits = 1.5 bytes, already within 2 bytes). Sample 2: '6 1' / '2 1 2 3 4 3' -> 2.
Constraints: 1 <= n <= 4 * 10^5, 1 <= I <= 10^8.
Format · Online assessment.
Community answers
Related courses


