背包。

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <ctime>
#include <set>
#include <map>
#define fo(i,j,k) for(int i(j);i<=k;i++)
#define fd(i,j,k) for(int i(j);i>=k;i--)
#define go(i,k) for(int i(head[k]),v(e[i].to);i;i(e[i].nxt),v(e[i].to))
using namespace std;
typedef long long ll;
typedef double db;
const int inf=0x3f3f3f3f;
inline int rd() {
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-') f=-1;ch=getchar();}
    while(isdigit(ch)) x=x*10+(ch^48),ch=getchar();
    return x*f;
}
const int N=305;
int n,a[N],sum;bool f[100005];
int main() {
#ifdef HSZ
    freopen(".in","r",stdin);
    freopen(".out","w",stdout);
#endif
    n=rd();
    fo(i,1,n) a[i]=rd(),sum+=a[i];
    int mid=sum>>1,ans=0;
    sort(a+1,a+1+n);
    f[0]=1;
    fd(i,n,1)
        fd(j,sum,a[i]) {
            f[j]|=f[j-a[i]];
            if(j>mid&&f[j]&&j-a[i]<=mid) {
                ans=max(ans,j);
            }
        }
    cout<<ans<<endl;
    return 0;
}

相关文章:

  • 2022-01-22
  • 2022-02-26
  • 2021-11-25
  • 2021-07-07
  • 2021-06-07
  • 2021-05-31
  • 2022-12-23
猜你喜欢
  • 2021-10-08
  • 2022-12-23
  • 2021-10-17
  • 2021-09-20
  • 2022-12-23
  • 2021-08-08
  • 2021-10-06
相关资源
相似解决方案