老师布置的暑假作业看不懂怎么办?

你写出来没

没有

嗯???

你做出来了

666,我也没A

你好啊

给我点思路呗

还在吗

还在

40 分,尽力了,(尽管班里改的)

#include <bits/stdc++.h>
#include <algorithm>
#define LL long long
using namespace std;
const LL N=2e5+1;
LL n,T,a[N];
int main(){
	cin.tie(0)->sync_with_stdio(0); 
	cin>>T;
	while(T--){
		LL ans=0,x=0,k=0;
		cin>>n;
		for(int i=1; i<=n; i++) cin>>a[i];
		sort(a+1,a+n+1);
		LL l=1,r=n;
		for(; l<r; l++){
			if(l==r-1){
				bool f=0;
				while(a[l]){
					if(k >= a[r]){
						ans+=k+1; 
						f=1;break; 
					} 
					k++; a[l]--;
				}
                if(f) r--;
    			else l++;
    			k=0;
    			break;
			} 
			k+=a[l];
			if(k >= a[r]){
				k-=a[r];
				ans+=a[r]+1;
				r--;
			}
		}
        if(l==r){
        	if(a[r]+k==1) ans++;
			else {
				LL p=a[r];
				while(1){
					if(k >= p){
						ans+=k+1;
						break; 
					}
	                k++; p--;
				}
			}
		}
		cout<<ans<<"\n";
	}
	return 0;
}



药肝血窝哦!

@栗子酱 回老帖?