1 条题解

  • 0
    @ 2026-5-31 16:21:35
    #include<bits/stdc++.h>
    using namespace std;
    #define int long long
    const int N=2e5+10;
    int a[N];
    signed main()
    {
    	int n,d,p;cin>>n>>d>>p;
    	for(int i=1;i<=n;i++)cin>>a[i];
    	sort(a+1,a+n+1,[](int x,int y){return x>y;});
    	int ans=0;
    	for(int i=1;i<=n;i+=d)
    	{
    		int sum=0;
    		for(int j=i;j<=min(n,i+d-1);j++)sum+=a[j];
    		if(sum>p)ans+=p;
    		else
    		{
    			for(int j=i;j<=n;j++)ans+=a[j];
    			cout<<ans;
    			return 0;
    		}
    	}
    	cout<<ans;
    	return 0;
    }
    • 1

    信息

    ID
    8845
    时间
    2000ms
    内存
    1024MiB
    难度
    2
    标签
    递交数
    34
    已通过
    23
    上传者