-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathValentineVex.cpp
130 lines (118 loc) · 3.16 KB
/
ValentineVex.cpp
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include<bits/stdc++.h>
using namespace std;
#define ll long long
pair<ll,ll> Solve(priority_queue<ll> pEven ,priority_queue<ll> pOdd,int mask){
ll ans1 =0;
ll ans2=0;
int count=1;
bool f1=0,f2=0;
bool s1=0,s2=0;
switch(mask){
case 0: f1=0, f2=0;
break;
case 1: f1=0, f2=1;
break;
case 2: f1=1,f2=0;
break;
case 3: f1=1,f2=1;
break;
}
// cout<<f1<<" "<<f2<<endl;
while (s1==0 || s2==0){
if(f1==0){
if(!pEven.empty()){
ans1+=pEven.top();
pEven.pop();
if(f1==0){
f1=1;
}else{
f1=0;
}
}
else{
s1=1;
}
}else{
if(!pOdd.empty()){
ans1+=pOdd.top();
pOdd.pop();
if(f1==0){
f1=1;
}else{
f1=0;
}
}else{
s1=1;
}
}
if(f2==0){
if(!pEven.empty()){
ans2+=pEven.top();
pEven.pop();
if(f2==0){
f2=1;
}else{
f2=0;
}
}
else{
s2=1;
}
}else{
if(!pOdd.empty()){
ans2+=pOdd.top();
pOdd.pop();
if(f2==0){
f2=1;
}else{
f2=0;
}
}else{
s2=1;
}
}
}
// cout<<ans1<<" "<<ans2<<endl;
return {ans1,ans2};
}
int main(){
int t;
cin >> t;
while(t--){
int n;
cin>>n;
priority_queue<ll> pEven,pOdd;
for(int i=0;i<n;i++){
ll temp;
cin >> temp;
if(temp%2==0){
pEven.push(temp);
}else{
pOdd.push(temp);
}
}
vector<pair<ll,ll>> ans;
for(int i=0;i<4;i++){
ans.push_back(Solve(pEven,pOdd,i));
}
int idx=-1;
ll score1=INT_MIN,score2=INT_MIN;
if(ans[0].second>ans[1].second){
score1=ans[0].first;
}else if(ans[0].second==ans[1].second){
score1=max(ans[0].first,ans[1].first);
}
else{
score1=ans[1].first;
}
if(ans[2].second>ans[3].second){
score2=ans[2].first;
}else if(ans[2].second==ans[3].second){
score2=max(ans[2].first,ans[3].first);
}
else{
score2=ans[3].first;
}
cout<<max(score2,score1)<<endl;
}
}