Codeforces Round #610 (Div. 2)
程序员文章站
2022-09-14 14:45:21
DP#includeusing namespace std;const int N=5e5+100;int a[N],n,m,k;int res[N];int f[N];int t;int main(){ ios::sync_with_stdio(false);// freopen("data.in","r",stdin); //从文件data.in中读入数据 // freopen("AC.out...
DP
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+100;
int a[N],n,m,k;
int res[N];
int f[N];
int t;
int main()
{
ios::sync_with_stdio(false);
// freopen("data.in","r",stdin); //从文件data.in中读入数据
// freopen("AC.out","w",stdout); //输出的结果存在ZhengJie.out文件中
cin>>t;
while(t--)
{
cin>>n>>m>>k;
for(int i=1;i<=n;i++) cin>>a[i];
sort(a+1,a+1+n);
for(int i=1;i<=n;i++) res[i]=res[i-1]+a[i];
for(int i=k;i<=n;i++) res[i]=res[i-k]+a[i];
int p;
for(int i=0;i<=n;i++) if(m>=res[i]) p=i;
cout<<p<<endl;
}
}
本文地址:https://blog.csdn.net/csdn_ggboy/article/details/107197844
推荐阅读
-
Codeforces Round #655 (Div. 2) A. Omkar and Completion
-
Codeforces Round #656 (Div. 3)D. a-Good String(递归+dfs)
-
Codeforces Round #487 (Div. 2)
-
CodeForces 1324 - Codeforces Round #627 (Div. 3)
-
Codeforces Round #649 (Div. 2)-B. Most socially-distanced subsequence(思维)
-
Codeforces Round #649 (Div. 2) C-Ehab and Prefix MEXs
-
Educational Codeforces Round 71 (Rated for Div. 2)E. XOR Guessing
-
Codeforces Round #659 (Div. 2) A. Common Prefixes(字符串,思维)
-
Codeforces Round #610 (Div. 2)
-
Codeforces Round #670 (Div. 2)