测试一发

#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
long long sum;
long long tot;
long long k=1;
long long a[100005];
int n,m;
int main()
{
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];      //记录方块总数
    }
    sort(a,a+n);        //排序
    if(n==1)
    cout<<0;            //如果只有一排的话,直接输出0
    else {
    for(int i=0;i<n;i++)
    {
        if(i==n-1)      //最后一排特判一下,把之后的全部加上
        {
            if(a[i]<=k)
            tot++;
            else tot+=(a[i]-k+1);
            break;
        }
        if(a[i]>=k)
        {
            k++;
            tot++;
        }
        else tot++;
    }
    cout<<sum-tot;      //用总数减去要保留的就是所求结果要拿走的
    }
    return 0;
}
//k是我讲的现在考虑放在第几行

猜你喜欢

转载自www.cnblogs.com/laioue/p/10048548.html