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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值