Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int min(int c, int b){
- if (c < b)
- return c;
- return b;
- }
- int abs(int num){
- if (num >= 0)
- return num;
- return -num;
- }
- int input_numbers[20];
- int result = 100001;
- void collect( int i, int s1, int s2, int n) {
- if (i == n) {
- result = abs(s1 - s2) < result ? abs(s1 - s2) : result;
- }
- else {
- collect(i + 1, s1 + input_numbers[i], s2, n);
- collect(i +1 , s1, s2 + input_numbers[i], n);
- }
- }
- int main(){
- int n;
- std::cin >> n;
- for (int i = 0; i < n; ++i)
- std::cin >> input_numbers[i];
- collect(0, 0, 0, n);
- std::cout << result;
- }
Advertisement
Add Comment
Please, Sign In to add comment