容易为本题的弱化版CF1786C想出一个贪心:
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,a[1000000];
signed main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%lld",&n);
for(int i=1;i<=n;i++)
scanf("%lld",&a[i]);
sort(a+1,a+n+1);
int p=0,ans=0;
for(int i=1;i<=n;i++){
if(p<a[i])
p++;
ans+=a[i]-p;
}
printf("%lld\n",ans);
}
}
加强版的前缀询问等于单点插入全局查询。
标签:int,题解,scanf,CF1786C,CF1786E,long From: https://www.cnblogs.com/celerity/p/17113890.html