比赛 2026.9.12 评测结果 AAAAAAAAAA
题目名称 分饼干 最终得分 100
用户昵称 zcx 运行时间 1.214 s
代码语言 C++ 内存使用 18.97 MiB
提交时间 2026-09-12 09:06:42
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
using namespace std;

const int V = 1e6 + 5;
const int base = 5e5;
const int N = 55;

int n;
int f[V],g[V];

signed main()
{
    freopen("cookie.in","r",stdin);
    freopen("cookie.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    memset(f,-0x3f,sizeof(f));
    memset(g,-0x3f,sizeof(g));
    g[base] = 0;
    for(int i = 1;i <= n;i++){
        int x;cin>>x;
        for(int j = 0;j <= V - 5;j++) if(j + x <= V - 5) f[j + x] = max(f[j + x],g[j] + x);
        for(int j = 0;j <= V - 5;j++) if(j - x >= 0) f[j - x] = max(f[j - x],g[j]);
        for(int j = 0;j <= V - 5;j++) g[j] = f[j];
    }
    
    cout<<f[base]<<'\n';
    
    return 0;
 }