| 比赛 |
2026.9.12 |
评测结果 |
AAAAAAAAAA |
| 题目名称 |
分饼干 |
最终得分 |
100 |
| 用户昵称 |
2_16鸡扒拌面 |
运行时间 |
0.843 s |
| 代码语言 |
C++ |
内存使用 |
10.31 MiB |
| 提交时间 |
2026-09-12 12:00:39 |
显示代码纯文本
#include<bits/stdc++.h>
#define SNSNMO 500010
#define ll long long
using namespace std;
int n,sum=0;
int a[SNSNMO],dp[SNSNMO*2],ndp[SNSNMO*2];
int main()
{
freopen("cookie.in","r",stdin);
freopen("cookie.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
cin>>n;
for(int i=1;i<=n;++i)
{
cin>>a[i];
sum+=a[i];
}
memset(dp,0xc0,sizeof(dp));
dp[sum]=0;
for(int i=1;i<=n;++i)
{
int x=a[i];
for(int j=0;j<=2*sum;++j) ndp[j]=dp[j];
for(int j=0;j<=2*sum;++j)
{
if(dp[j]==(int)0xc0c0c0c0) continue;
if(j+x<=2*sum) ndp[j+x]=max(ndp[j+x],dp[j]+x);
if(j-x>=0) ndp[j-x]=max(ndp[j-x],dp[j]);
}
for(int j=0;j<=2*sum;++j) dp[j]=ndp[j];
}
cout<<max(dp[sum],0)<<'\n';
return 0;
}