#include <stdio.h>
int natural_num_sum(int n)
{
return (n + 1) * n / 2;
}
int sum_lower_equal(const int *arr, int arr_size, int lower_equal)
{
int sum = 0;
for (int i = 0; i < arr_size; i++) {
if (arr[i] <= lower_equal) {
sum += arr[i];
}
}
return sum;
}
int sum(const int *arr, int arr_size) {
int sum = 0;
for (int i = 0; i < arr_size; i++) {
sum += arr[i];
}
return sum;
}
void solve_2(const int *arr, int arr_size)
{
int n = arr_size + 2;
int sum_x_y = natural_num_sum(n) - sum(arr, arr_size);
int x_is_lower_equal = sum_x_y / 2;
int x = natural_num_sum(x_is_lower_equal) - sum_lower_equal(arr, arr_size, x_is_lower_equal);
int y = sum_x_y - x;
printf("x = %d, y = %d\n", x
, y
); }
int main(void) {
const int test[] = {1, 4, 3, 2};
solve_2(test, sizeof(test)/sizeof(test[0]));
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgbmF0dXJhbF9udW1fc3VtKGludCBuKQp7CglyZXR1cm4gKG4gKyAxKSAqIG4gLyAyOwp9CgppbnQgc3VtX2xvd2VyX2VxdWFsKGNvbnN0IGludCAqYXJyLCBpbnQgYXJyX3NpemUsIGludCBsb3dlcl9lcXVhbCkKewoJaW50IHN1bSA9IDA7CgkKCWZvciAoaW50IGkgPSAwOyBpIDwgYXJyX3NpemU7IGkrKykgewoJCWlmIChhcnJbaV0gPD0gbG93ZXJfZXF1YWwpIHsKCQkJc3VtICs9IGFycltpXTsKCQl9Cgl9CgkKCXJldHVybiBzdW07Cn0KCmludCBzdW0oY29uc3QgaW50ICphcnIsIGludCBhcnJfc2l6ZSkgewoJaW50IHN1bSA9IDA7CgkKCWZvciAoaW50IGkgPSAwOyBpIDwgYXJyX3NpemU7IGkrKykgewoJCXN1bSArPSBhcnJbaV07Cgl9CgkKCXJldHVybiBzdW07Cn0KCnZvaWQgc29sdmVfMihjb25zdCBpbnQgKmFyciwgaW50IGFycl9zaXplKQp7CglpbnQgbiA9IGFycl9zaXplICsgMjsKCWludCBzdW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