B. Views Matter

链接

[http://codeforces.com/contest/1061/problem/B]

题意

问你最多去掉多少块使得从上和右看,投影图不变

分析

注意细节,尤其第一列

代码

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[100010];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    //freopen("in.txt","r",stdin);
    ll n,m,i;
    while(cin>>n>>m){
        for(i=0;i<n;i++)
        cin>>a[i];
        sort(a,a+n);
        ll ma=a[n-1];
        ll sum=0,j=1;
        for(i=0;i<n;i++){
            if(i==n-1&&j<=ma) sum+=j-1;
            else if(a[i]>=j&&j<=ma&&i!=0) sum+=a[i]-1,j++;  
            else if(i==0&&a[i]>1) sum+=a[i]-1,j++;
            else if(i==0&&a[i]==1) j++;
            else if(a[i]>1) sum+=a[i]-1;
            //cout<<sum<<endl;  
        }
        cout<<sum<<endl;
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/mch5201314/p/10008617.html
今日推荐