Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define INF 100000000
- int n;
- int size[53];
- int sum = 0;
- int memo[53][100007];
- int dp(int pos, int tam){
- if(tam <= sum/2)
- return tam;
- if(pos == n)
- return -INF;
- if(memo[pos][tam] != -1)
- return memo[pos][tam];
- int a, b;
- a = dp(pos+1, tam-size[pos]);
- b = dp(pos+1, tam);
- return memo[pos][tam] = max(a,b);
- }
- int main(){
- cin >> n;
- for(int i = 0; i < n; i++){
- cin >> size[i];
- sum += size[i];
- }
- memset(memo, -1, sizeof(memo));
- int resp = dp(0, sum);
- cout << resp << " " << sum - resp;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement