Source Code
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;


void solve(){
	int n, k;
	cin >> n >> k;
	vector<int> com(n+1, 0);
	for(int i = 1; i <= n; i++){
		cin >> com[i];
		com[i]+=com[i-1];
	}
	int x = 0, y;
	long long maxSum = 0;
	while(x <= n){
		y = x^k;
		if( x + y <= n){
			int left, right;
			left = com[x];
			right = com[n] - com[n-y];
			// cout << x << " " << y << " " << left << " " << right << endl;
	
			maxSum = max(maxSum, ll(left+right));
		}
		x++;
	}
	cout << maxSum << endl;
}

int main(){
	int t; cin >> t;
	while(t--)
		solve();
	return 0;
}
Copy
Midterms MohaDarkness
GNU G++17
67 ms
1.1 MB
Accepted