| Task: | Apple Division |
| Sender: | aalto26aw_007 |
| Submission time: | 2026-09-02 16:32:53 +0300 |
| Language: | C++ (C++20) |
| Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'int main()':
input/code.cpp:12:24: error: 'INT_MAX' was not declared in this scope
12 | int bestDiff = INT_MAX;
| ^~~~~~~
input/code.cpp:3:1: note: 'INT_MAX' is defined in header '<climits>'; did you forget to '#include <climits>'?
2 | #include <cmath>
+++ |+#include <climits>
3 | using namespace std;Code
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n, p[20];
cin >> n;
for(int i = 0; i < n; ++i){
cin>>p[i];
}
int bestDiff = INT_MAX;
for(int mask = 0; mask < (1 << n); ++mask){
int sumA = 0, sumB = 0;
for(int j = 0; j < n; j++){
if(mask & (1 << j)){
sumA += p[j];
}
else{
sumB += p[j];
}
}
int diff = abs(sumA - sumB);
if(diff < bestDiff) bestDiff = diff;
}
cout << bestDiff;
return 0;
}
