码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #523 (Div. 2) B. Views Matter

时间:2018-11-25 22:26:37      阅读:271      评论:0      收藏:0      [点我收藏+]

标签:lld   sort   一个   include   namespace   const   att   ons   影响   

B. Views Matter

题目链接https://codeforc.es/contest/1061/problem/B

题意:

给一个类似棋盘的东西,对于每一列都放有格子,问在无重力的条件下,最多可以抽取多少个格子,并且使纵向视图和横向视图保持原样。

 

题解:

这题还是采用贪心的方法,先排个序,这并不影响结果。

对于每一列,肯定有一个棋子来满足纵向视图,然后尽可能地将它往高处放来满足横向视图,前提是高度低于它的横向视图已经有棋子了。

 

代码如下:

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 100005;
int n,m;
int a[N];
ll sum = 0;
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++) cin>>a[i],sum+=a[i];
    sort(a+1,a+n+1);
    int y = 0,x = 0;
    for(int i=1;i<=n;i++){
        x++;
        if(a[i]>y) y++;
    }
    ll ans = 0;
    ans = a[n]-y+x;
    printf("%lld",sum-ans);
    return 0;
}

 

Codeforces Round #523 (Div. 2) B. Views Matter

标签:lld   sort   一个   include   namespace   const   att   ons   影响   

原文地址:https://www.cnblogs.com/heyuhhh/p/10017481.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!