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

#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

typedef long long int ll;

ll mod=1e9+7;
ll a[200010];
ll b[200010];
ll tc,i,j,k,n,m,x;
string s,s1,s2;

vector<ll> v;

int main(){

    IOS

    cin>>tc;

    while(tc--){
            cin>>n>>k;

            for(i=0;i<n;i++)
                cin>>a[i];

            ll l=n/2;
            ll r=n-l;
            ll mx=max(l,r);
            ll mn=min(l,r);

            while( (mx^mn)!=k ){
                if(mn!=0)
                    mn--;
                else
                    mx++;
            }

            ll p1=0,p2=0,s1=0,s2=0;

            for(i=0;i<mx;i++)
                p1+=a[i];

            for(i=0;i<mn;i++)
                p2+=a[i];

            for(i=n-1;i>=n-mx;i--)
                s1+=a[i];

            for(i=n-1;i>=n-mn;i--)
                s2+=a[i];

            cout<<max({p1+s2,p2+s1})<<endl;

            
    }

}
Copy
Midterms AshcoOoOdel
GNU G++17
15 ms
364 KB
Wrong Answer