Source Code
#include <iostream>
#include<bits/stdc++.h>
#include<unordered_map>
#define ll long long
using namespace std;
int main() {
    std::ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    int t; cin >> t;
    while (t--) {
		int n, k,a;
		cin >> n >> k;
		vector<ll>v(n+1);
		for (int i = 1; i <= n; i++) {
			cin >> a;
			v[i] = v[i - 1] + a;
		}
		ll ans = 0;
		for (int x = 1; x <= n; x++) {
			int y = k ^ x;
			if (x + y > n)continue;
			ans = max(ans, (v[x] + (v[n] - v[n - y])));
		}
		cout << ans << "\n";
    }
    return 0;
}
Copy
Midterms Walaa Abd Elhady
GNU G++17
16 ms
312 KB
Wrong Answer