CF1198A.MP3

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of nn non-negative integers.

If there are exactly KK distinct values in the array, then we need k=⌈log⁡2K⌉k = \lceil \log_{2} K \rceil bits to store each value. It then takes nknk bits to store the whole file.

To reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers l≤rl \le r, and after that all intensity values are changed in the following way: if the intensity value is within the range [l;r][l;r], we don't change it. If it is less than ll, we change it to ll; if it is greater than rr, we change it to rr. You can see that we lose some low and some high intensities.

Your task is to apply this compression in such a way that the file fits onto a disk of size II bytes, and the number of changed elements in the array is minimal possible.

We remind you that 11 byte contains 88 bits.

k=⌈log2K⌉k = \lceil log_{2} K \rceil is the smallest integer such that K≤2kK \le 2^{k}. In particular, if K=1K = 1, then k=0k = 0.

将声音数字化的一种常见方法是在特定的时间点记录声音强度。在每个时间点,强度被记录为一个非负整数。因此,我们可以将一个音频文件表示为一个包含 nn 个非负整数的数组。

若该数组中恰好有 KK 个不同的值,则存储每个值需要 k=⌈log⁡2K⌉k = \lceil \log_{2} K \rceil 位。于是,整个文件共需 nknk 位来存储。

为了减少内存占用,我们需要进行某种压缩。一种常用方法是减少可能的强度值数量。我们选取两个整数 l≤rl \le r,然后按如下方式修改所有强度值:若强度值落在区间 [l;r][l;r] 内,则保持不变;若强度值小于 ll,则将其改为 ll;若强度值大于 rr,则将其改为 rr。可以看出,我们因此损失了一些较低和较高强度的信息。

你的任务是以这种方式执行压缩,使得压缩后的文件能存入大小为 II 字节的磁盘,并使数组中被修改的元素个数尽可能少。

请注意:11 字节包含 88 位。

k=⌈log⁡2K⌉k = \lceil \log_{2} K \rceil 是满足 K≤2kK \le 2^{k} 的最小整数。特别地,若 K=1K = 1,则 k=0k = 0。

输入格式

The first line contains two integers nn and II (1≤n≤4⋅1051 \le n \le 4 \cdot 10^{5}, 1≤I≤1081 \le I \le 10^{8}) — the length of the array and the size of the disk in bytes, respectively.

The next line contains nn integers aia_{i} (0≤ai≤1090 \le a_{i} \le 10^{9}) — the array denoting the sound file.

第一行包含两个整数 nn 和 II(1≤n≤4⋅1051 \le n \le 4 \cdot 10^{5},1≤I≤1081 \le I \le 10^{8}),分别表示数组的长度和磁盘容量(单位:字节)。

第二行包含 nn 个整数 aia_{i}(0≤ai≤1090 \le a_{i} \le 10^{9}),表示声音文件的数组。

输出格式

Print a single integer — the minimal possible number of changed elements.

输出一个整数——被修改元素的最小可能数量。

输入输出样例

  • 输入#1

    6 1
    2 1 2 3 4 3

    输出#1

    2
  • 输入#2

    6 2
    2 1 2 3 4 3

    输出#2

    0
  • 输入#3

    6 1
    1 1 2 2 3 3

    输出#3

    2

说明/提示

In the first example we can choose l=2,r=3l=2, r=3. The array becomes 2 2 2 3 3 3, the number of distinct elements is K=2K=2, and the sound file fits onto the disk. Only two values are changed.

In the second example the disk is larger, so the initial file fits it and no changes are required.

In the third example we have to change both 1s or both 3s.

在第一个例子中,我们可以选择 l=2,r=3l=2, r=3。数组变为 2 2 2 3 3 3,不同元素的个数为 K=2K=2,该音频文件可以存入磁盘。仅需修改两个值。

在第二个例子中,磁盘容量更大,因此原始文件即可存入磁盘,无需任何修改。

在第三个例子中,我们必须将两个 1 或两个 3 全部修改。

输入解题思路,AI测评打分。不知道怎么写?

首页