60分的应该是没开long long
查看原帖
60分的应该是没开long long
1413585
Alhandsome11楼主2024/8/6 16:20
#include <bits/stdc++.h>
using namespace std;
const int N = 10005;

long long w[N] = {0};
long long b[N] = {0};
long long C = 0;
long long maxn,cur = 0;
void dfs(long long cur,int index)
{
    if(cur + b[index] < maxn) return;
    maxn = cur < maxn ? maxn:cur;
    if(!index) return;
    if(cur + w[index] < C)
    {
        dfs(cur + w[index],index - 1);
    }
    dfs(cur,index-1);
}

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,i = 1;cin >> n >> C;
    while(i <= n)
    {
        cin >> w[i];
        if(w[i] > C)
            break;
        b[i] = b[i - 1] + w[i];
        i++;
    }
    dfs(0,i - 1);
    cout << maxn;
    return 0;
}
2024/8/6 16:20
加载中...