StellarSeating Maximization
Practice
4 (1 votes)
Max subarray sum
Introduction to dynamic programming 1
Dynamic programming
Algorithms
Problem
77% Success 741 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

In the realm of StarRail, a grand interstellar train known for its luxurious compartments, each carriage comes with a unique seating arrangement denoted by an array \(S\). The array \(S\) represents the number of seats in each compartment, adding to the train's charm and comfort.

A brilliant engineer named Nova has been entrusted with the task of enhancing the seating capacity of the StarRail. 

Nova possesses a unique ability: he can perform the following operation atmost once. This operation enables Nova to select two compartments, denoted by indices \(L\) and \(R\), and modify the number of seats in all compartments between \(L\) and \(R\) (inclusive) by performing a bitwise \(XOR\) operation with value \(Y\), where \(1 \leq L \leq R \leq N\).

Mathematically, the operation can be expressed as follows: \(S[i] = S[i] \oplus Y\) (\(\oplus\) denotes the bitwise the \(XOR\) operation), where \(L \leq i \leq R\).

Nova's ultimate objective is to maximize the overall seating capacity of StarRail using this operation.

Help Nova determine the maximum number of passengers that can travel on the StarRail by finding the optimal compartments to perform the operation on and maximizing the total seating capacity.

Input Format:

The first line of input data contains single integer \(T\) — the number of test cases in the test.

For each testcase the first line contains two integers \(N\) - the number of compartment in StarRail and \(Y\) - the number given to Nova.

The second line contains \(N\) integers \(S_1,S_2, ...., S_N\) – the number of seats in each compartment.

Note: Sum of all \(N\) doesn’t exceed \(10^6\)

Output Format:

For each testcase output a single integer - the maximum number of passengers that can travel on the StarRail.

Constraints:

\(1 \leq T \leq 100 \\ 1 \leq N \leq 10^5 \\ 1 \leq Y \leq 10^9 \\ 1 \leq S[i] \leq 10^9 \\\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
9 votes
Tags:
AlgorithmsDynamic Programming
Points:30
13 votes
Tags:
Dynamic ProgrammingAlgorithmsIntroduction to Dynamic Programming 1
Points:30
12 votes
Tags:
Introduction to Dynamic Programming 1BitmaskDynamic ProgrammingAlgorithms