| Innopolis Open 2024. Final round |
|---|
| Finished |
Students of Innopolis have come up with a new board game. The game is cooperative, meaning that players must work together to achieve a specific goal. One of the phases of the game involves distributing resources.
The game is designed for exactly $$$n$$$ players, and during the resource distribution phase $$$n$$$ cards with integers, ordered in non-decreasing order, are distributed among the players in order. Let $$$a_i$$$ be the number received by the $$$i$$$-th player (then $$$a_i \le a_{i+1}$$$ for all $$$i \le n - 1$$$). We call the set of three numbers $$$\{a_{i-1}, a_i, a_{i+1}\}$$$, i.e., the number written on his card and the two numbers of his neighbors, the options of the $$$i$$$-th player. The players sit in a circle, so for the first player instead of $$$a_{i-1}$$$ the first option will be $$$a_n$$$, and for the $$$n$$$-th player instead of $$$a_{i+1}$$$ the third option will be $$$a_1$$$.
Each player must choose exactly one of the available options and receive exactly that many resources from the bank. Then, the bitwise "AND" operation (the '&' operation) is performed on the two remaining options and the resulting number of points is added to the players' score for this round. For example, if a player has the options $$$\{2, 5, 11\}$$$ and chooses to take $$$5$$$ resources, he gets $$$2\ \&\ 11 = 0010_2\ \&\ 1011_2 = 2$$$ points. To successfully move on to the next phase of the game:
Help the players make their choices and successfully move on to the next phase. Note that it is not necessary to maximize the amount of resources taken within this upper limit; only the number of points needs to be maximized.
The first line of input contains two space-separated integers $$$n$$$ and $$$X$$$ — the number of players and the limit on the "extra" number of resources ($$$3 \le n \le 300$$$; $$$0 \le X \le 10^5$$$).
The second line contains $$$n$$$ space-separated integers $$$a_i$$$ — the values written on the cards given to the players ($$$0 \le a_i \le 10^5$$$; $$$a_i \le a_{i+1}$$$).
Output a single integer — the maximum number of points that the players can earn in this phase.
Points for each subtask are awarded only if all tests for that subtask and any necessary subtasks are successfully passed.
| Subtask | Points | Constraints | Necessary subtasks | Feedback policy |
| 0 | – | examples | full | |
| 1 | 13 | $$$n \le 14$$$ | 0 | full |
| 2 | 8 | $$$1 \le a_i \le 2$$$ for all $$$i$$$ | first error | |
| 3 | 10 | $$$a_i \le 3$$$ for all $$$i$$$ | 2 | first error |
| 4 | 12 | $$$a_n - a_1 \le 1$$$ | 2 | first error |
| 5 | 17 | $$$a_i\ \&\ a_{i+1} = a_i$$$ for all $$$i$$$ | first error | |
| 6 | 16 | $$$a_i \le 200$$$ for all $$$i$$$ | 0, 2, 3 | first error |
| 7 | 24 | no additional constraints | 0 – 6 | first error |
4 01 2 4 8
0
4 03 6 12 24
22
7 31 2 3 4 5 6 7
26
In the first example $$$a_i\ \&\ a_j = 0$$$ for $$$i \ne j$$$, so it is not possible to score any points.
In the second example the players should take resources in quantities of $$$24$$$, $$$3$$$, $$$6$$$, and $$$3$$$ respectively. Then the number of points is equal to $$$(3\ \&\ 6) + (6\ \&\ 12) + (12\ \&\ 24) + (12\ \&\ 24) = 2 + 4 + 8 + 8 = 22$$$.
| Name |
|---|


