-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLENTMO.cpp
More file actions
60 lines (51 loc) · 1.18 KB
/
LENTMO.cpp
File metadata and controls
60 lines (51 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
long long t,n,k,x,maxi,sum,sum2,sum1,a[200000],b[200000];
int main()
{
cin>>t;
while(t--){
maxi=0;
sum=0;
sum1=0;
sum2=0;
v.clear();
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
sum+=a[i];
}
cin>>k>>x;
for(int i=0;i<n;i++){
b[i]=a[i]^x;// xor
v.push_back(b[i]-a[i]);
}
sort(v.begin(),v.end());
reverse(v.begin(),v.end());
if(k%2==0){
for(int i=0;i<v.size();i++){
sum1+=v[i];
//even case
if(i%2==1){
maxi=max(maxi,sum1);
}
}
}else{
for(int i=0;i<n;i++){
sum2+=v[i];
maxi=max(maxi,sum2);
}
}
if(n==k){
long long sum3=0;
for(int i=0;i<n;i++){
sum3+=b[i];
}
cout<<max(sum3,sum)<<endl;
continue;
}
cout<<sum+maxi<<endl;
}
return 0;
}