QOJ.ac
QOJ
ID | 提交记录ID | 题目 | Hacker | Owner | 结果 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|
#1603 | #941925 | #7403. Subset Sum | max0810 | Hanghang | Success! | 2025-03-18 20:07:49 | 2025-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 Sum | Hanghang | WA | 650ms | 3968kb | C++20 | 567b | 2025-03-18 20:04:27 | 2025-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;
}