背包问题,可以转化为0.1,递增排序好,选定两个,从最大的开始比较,给较小的加上第三大,以此循环,最后可以输出
#include <iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
int
main(){
int
n;
vector<
int
> v;
while
(cin >> n){
cin.get();
v.push_back(n);
}
sort(v.begin(),v.end());
int
sum=accumulate(v.begin(),v.end(),
0
);
int
l=v.size();
int
f=v[l-
1
],s=v[l-
2
];
if
(l>=
3
){
for
(
int
i=l-
3
;i>=
0
;--i){
if
(f>s)s+=v[i];
else
f+=v[i];
}}
if
(f>s) cout<<f<<
","
<<sum-f;
else
cout<<s<<
","
<<f;
}