Source Code
#include <iostream>
#include<algorithm>
using namespace std;
long long p[200002], s[200002];
int main()
{
	long long t, n, k;

	cin >> t;

	while (t--)
	{
		long long mx = -1e18;

		cin >> n >> k;

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

		for (int i = n; i >= 1; i--) s[i] += s[i + 1];

		reverse(s, s + n + 1);

		for (int i = 0; i <= n; i++)
		{
			for (int j = 0; j <= n; j++)
			{
				if (i + j <= n && (i ^ j) == k)
				{
					if ((p[i] + s[j - 1]) > mx)
						mx = (p[i] + s[j - 1]);
				}

			}
		}

		cout << mx << "\n";
	}
}
Copy
Midterms OmarNasr
GNU G++17
59 ms
312 KB
Wrong Answer