QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#1603#941925#7403. Subset Summax0810HanghangSuccess!2025-03-18 20:07:492025-03-18 20:07:49

详细

Extra Test:

Wrong Answer
time: 0ms
memory: 3840kb

input:

1
6 22
5 5 5 8 9 10

output:

20

result:

wrong answer 1st numbers differ - expected: '22', found: '20'

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#941925#7403. Subset SumHanghangWA 650ms3968kbC++20567b2025-03-18 20:04:272025-03-18 20:12:26

answer

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N=2e4+3;
int n,m,H,a[N],f[N],g[N];
void Max(int &x,int y){if(x<y)x=y;}
void Solve()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+n+1);H=a[n];
	memset(f,-0x3f,sizeof(f));f[0]=0;
	for(int t=1;t<=n;t++)
	{
		memcpy(g,f,sizeof(g));
		for(int i=0;i<H;i++)if(g[i]+a[t]<=m)
			Max(f[(i+a[t])%H],g[i]+a[t]);
	}
	cout<<*max_element(f,f+H)<<endl;
}
int main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int T;cin>>T;
	while(T--)Solve();
	return 0;
}