题解归档 - cf2236A

题解归档 - cf2236A

本文由 cf-code 本地题解库自动归档;公开内容以本地 AC/验证版本为准。

思路

pattern:
range minimization
claim:
The minimum valid k is max(h)-min(h)+1.
why:
If the final common height is H, every tower needs 1<=H-h_i<=k, so H must be at least max(h)+1 and k must be at least H-min(h). The best choice is H=max(h)+1.
check:
For n<=5 and h_i<=6 this formula can be brute-forced by trying H and k directly.
edge:
If all heights are equal, each tower still must be increased by at least 1, so the answer is 1.

代码

来源:problems/cf2236A/solution.cpp

/* Author: likely
 * Time: 2026-06-19 10:49:39
**/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn=10;
ll p[maxn+5],n,i,j,k,mn,mx;
int main(){
    ll t;
    scanf("%lld",&t);
    while(t--){
        scanf("%lld",&n);
        mn=1e18;
        mx=0;
        for(i=1;i<=n;i++){
            scanf("%lld",&p[i]);
            mn=min(mn,p[i]);
            mx=max(mx,p[i]);
        }
        printf("%lld\n",mx-mn+1);
    }
    return 0;
}
~  ~  The   End  ~  ~


 赏 
感谢您的支持,我会继续努力哒!
支付宝收款码
tips
文章二维码 分类标签:归档TypechoAutoUpload
文章标题:题解归档 - cf2236A
文章链接:https://www.fangshaonian.cn/archives/303/
最后编辑:2026 年 6 月 28 日 19:06 By 方少年
许可协议: 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)
(*) 3 + 5 =
快来做第一个评论的人吧~