标签:max -- mes cst pac cstring can main std
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,a[100005],dp[100005],sum,half,ans;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
sum+=a[i];
}
half=sum>>1;
sort(a+1,a+n+1);
for(int i=n;i>=1;i--){
for(int j=sum;j>=0;j--){
if(j>=a[i])dp[j]=max(dp[j],dp[j-a[i]]+a[i]);
if(dp[j]>half&&dp[j]-a[i]<=half){
ans=max(ans,dp[j]);
}
}
}
printf("%d\n",ans);
}
标签:max -- mes cst pac cstring can main std
原文地址:https://www.cnblogs.com/Y15BeTa/p/11334413.html