Submission details
Task:Apple Division
Sender:aalto25a_001
Submission time:2025-09-03 16:22:12 +0300
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:17:19: error: 'LLONG_MAX' was not declared in this scope
   17 |   long long ans = LLONG_MAX;
      |                   ^~~~~~~~~
input/code.cpp:2:1: note: 'LLONG_MAX' is defined in header '<climits>'; did you forget to '#include <climits>'?
    1 | #include <iostream>
  +++ |+#include <climits>
    2 |

Code

#include <iostream>

using namespace std;

const int N = 25;

int n;
int p[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  long long ans = LLONG_MAX;
  for (int mask = 0; mask < (1 << n); mask++) {
    long long x = 0, y = 0;
    for (int i = 0; i < n; i++) {
      if (mask >> i & 1) x += p[i];
      else y += p[i];
    }
    ans = min(ans, llabs(x - y));
  }
  cout << ans << '\n';
  return 0;
}