1 #include <iostream> 2 #include <vector> 3 #include <algorithm> 4 #include <cstring> 5 #include <cstdio> 6 7 using namespace std; 8 9 int main(){ 10 int n; 11 cin >>n; 12 vector<int> stone(n+1,0); 13 int sum = 0; 14 for(int i = 1; i <= n; i ++){ 15 cin >> stone[i]; 16 sum += stone[i]; 17 } 18 vector<int> dp(sum/2+1,0); 19 for(int i =1; i <= n; i ++){ 20 for(int j = sum/2; j >= stone[i]; j --){ 21 dp[j] = max(dp[j-stone[i]]+stone[i],dp[j]); 22 } 23 } 24 cout<<sum-2*dp[sum/2]<<endl; 25 26 return 0; 27 }