Source Code
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define		_Narutoo ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define		all(a) a.begin(), a.end()
#define		rall(a) a.rbegin(), a.rend()
#define		endl "\n"
#define		ll long long
#define		uniquee(v) v.resize(unique(v.begin(),v.end())-v.begin())
ll      	OO = 1073741824;
ll gcd(ll x, ll y) { return(!y ? x : gcd(y, x%y)); }
ll lcm(ll x, ll y) { return x / gcd(x, y)*y; }
void File() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int main()
{
	_Narutoo;
	File();
	ll t = 1;
	cin >> t;
	while (t--)
	{
		ll n, k,maxi= INT_MIN;
		cin >> n >> k;

		vector <ll >v(n + 20), v2(n + 20),nu(n);
		for (auto&it : nu)cin >> it;
		for (int i = 1; i < nu.size() + 1; i++)
		{
			v[i] = nu[i - 1];
			v2[i] = nu[i - 1];
		}
		for (int i = 1; i < nu.size() + 1; i++)
		{
			v[i] += v[i - 1];
		}
		for (int i = nu.size() - 1; i > 0; i--)
		{
			//  cout << v2[i]<< endl;
			v2[i] += v2[i + 1];
			// cout << "After  "<< v2[i]<<endl;
		}
		int cnt = 0;
		for (int i = 1; i < nu.size(); i++)
		{
			// cout << v[i]<< "  "<< v2[i+1]<< endl;
			int y = k ^ i;
		//	cout << i << "   " << y << endl;
			//cout << v[i] + v2[y] << endl;
			if ((i + y <= n))
			{
				//cout << "fdsgvd" << endl;
				if (v[i] + v[n]-v[n-y] > maxi)
					maxi = v[i] + v[n] - v[n - y];
			}
		}
		cout << maxi << endl;
	}
}
Copy
Midterms ZyadBahaa
GNU G++17
18 ms
324 KB
Wrong Answer