Codeforces Round #576 (Div. 1)Problem A.MP3

A. MP3

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 ?n non-negative integers.

If there are exactly ?K distinct values in the array, then we need ?=⌈log2?⌉k=⌈log2⁡K⌉ bits to store each value. It then takes ??nk 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≤r, and after that all intensity values are changed in the following way: if the intensity value is within the range [?;?][l;r], we don't change it. If it is less than ?l, we change it to ?l; if it is greater than ?r, we change it to ?r. 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 ?I bytes, and the number of changed elements in the array is minimal possible.

We remind you that 11 byte contains 88 bits.

?=⌈???2?⌉k=⌈log2K⌉ is the smallest integer such that ?≤2?K≤2k. In particular, if ?=1K=1, then ?=0k=0.

Input

The first line contains two integers ?n and ?I (1≤?≤4⋅1051≤n≤4⋅105, 1≤?≤1081≤I≤108) — the length of the array and the size of the disk in bytes, respectively.

The next line contains ?n integers ??ai (0≤??≤1090≤ai≤109) — the array denoting the sound file.

Output

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

Examples

input

Copy

6 1
2 1 2 3 4 3

output

Copy

2

input

Copy

6 2
2 1 2 3 4 3

output

Copy

0

input

Copy

6 1
1 1 2 2 3 3

output

Copy

2

Note

In the first example we can choose ?=2,?=3l=2,r=3. The array becomes 2 2 2 3 3 3, the number of distinct elements is ?=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.

感想:A题比B题的AC数少,Div1少见的场面,Div1的大佬们都被这题的题意给整蒙了,我当时打比赛的时候也是一脸懵,英语果然很重要啊。

思路:果断暴力枚举区间,找出最小值,先用num[],存储字符,我想到的是去重,排序,因为要记录每一种字符出现的次数

所以我就定义了一个结构体,(其实是我比较菜,不会set<node>),排好序以后,就开始枚举了,结果一直wa44,我的

算法有一个不严谨的地方,测试数据简直神仙,后来加了一个标记,完美AC。

#include<bits/stdc++.h>
using namespace std;
typedef  struct
{
    int num;
    int cnt;//num出现的次数
    int precnt;//记录前缀和
}x;
x xx[400005];
int main()
{
    int n,m;
    int num[400005];
    scanf("%d %d",&n,&m);
    m*=8,m/=n;
    if(m>=30)
    {
        printf("%d\n",0);
        return 0;
    }
    int k=1<<m;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&num[i]);
    }
    sort(num+1,num+n+1);
    int flag=0;
    xx[flag].num=num[1],xx[flag].cnt=1;
    for(int i=2;i<=n;i++)//手动去重,我好菜
    {
        if (xx[flag].num == num[i])xx[flag].cnt++;
        else {

            if (flag) {
                xx[flag].precnt = xx[flag - 1].precnt + xx[flag].cnt;
            } else {
                xx[flag].precnt = xx[flag].cnt;
            }
            flag++;
            xx[flag].num = num[i];
            xx[flag].cnt = 1;
        }
    }
    xx[flag].precnt=xx[flag].cnt+xx[flag-1].precnt;
    long long ans=0;
    long long t0tal=xx[flag].precnt;
    int flag2=1;
    for(int i=0;i+k-1<=flag;i++)//从第一个开始枚举区间
    {
        int t=i+k-1;
        long long tt;
        if(i==0)
        {
            tt=xx[t].precnt;//前缀和的作用开始显现啦
        } else
        {
            tt=xx[t].precnt-xx[i-1].precnt;
        }
        ans=max(ans,tt);
        flag2=0;
    }
    if(flag2)ans=n;//wa44
    printf("%lld\n",n-ans);
        return 0;
}
发布了10 篇原创文章 · 获赞 6 · 访问量 1790

猜你喜欢

转载自blog.csdn.net/Kris_Kris/article/details/97921991