#P6747. Maximize k for Safe Hyperion Activation

    ID: 19955 Type: Default 1000ms 256MiB

Maximize k for Safe Hyperion Activation

Maximize k for Safe Hyperion Activation

Matt Horan wants to initiate a maneuver on the Hyperion. In order to do so, he must activate all n ignition points on the ship. Each ignition point i has an energy value of ai. To activate, Matt consumes k × n units of a special substance. These k × n units are evenly distributed among the n ignition points so that each point receives exactly k units. After receiving k units, the i-th point generates a high-energy output of \[ a_i \operatorname{xor} k \] energy units, where \(\operatorname{xor}\) represents the bitwise exclusive OR operation. The total high-energy output is \[ S = \sum_{i=1}^n (a_i \operatorname{xor} k)\] However, if \(S\) exceeds the safety limit m, the Hyperion will be overloaded and explode. To perform the maneuver as fast as possible, Matt wants to use as much substance as possible (i.e. choose the maximum possible k) while keeping \(S \le m\). If under any circumstance the ship cannot safely be activated, output -1.

Input/Output Note: All numbers are non-negative integers. It is guaranteed that if a safe activation is possible, then there exists a maximum k satisfying \(\sum_{i=1}^n (a_i \operatorname{xor} k) \le m\).

inputFormat

The first line contains two integers n and m — the number of ignition points and the safety limit, respectively.

The second line contains n space‐separated integers: a1, a2, ..., an.

outputFormat

Output a single integer — the maximum k such that \(\sum_{i=1}^n (a_i \operatorname{xor} k) \le m\). If no such k exists, output -1.

sample

1 0
5
5