Source Code
#include<iostream>
#include<algorithm>
#include<deque>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
#define OmarNasr {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
using namespace std;
long long p[200002], s[200002];
int main()
{
	long long t, n, k;
	cin >> t;

	while (t--)
	{
	    long long mx = 0;

		cin >> n >> k;
		for (int i = 1; i <= n; i++)
		{
			cin >> p[i];
			p[i] += p[i - 1];
		}
		int c = 1;
		s[n] = p[n];
		for (int i = n - 1; i >= 1; i--)
			s[c++] = p[n] - p[i];

		for (int i = 0; i <= n; i++)
		{
			int x = (k ^ i);
			if (1ll * i + x <= n)
			{
				//if ((i ^ j) == k)cout << i << " " << j << "\n";
				if ((p[i] + s[x]) > mx && (i ^ x) == k)
					mx = (p[i] + s[x]);
			}
		}

		cout << mx << "\n";
	}
}
Copy
Midterms OmarNasr
GNU G++17
75 ms
3.4 MB
Accepted