-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1144B - Parity Alternated Deletions.cpp
More file actions
99 lines (87 loc) · 1.54 KB
/
1144B - Parity Alternated Deletions.cpp
File metadata and controls
99 lines (87 loc) · 1.54 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
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
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <climits>
#include <queue>
#include <stack>
#include <ctype.h>
#include <set>
#include <unordered_map>
#define ll long long
#define pb push_back
#define ArrayMaxLen 100001
#define vi vector<int>
#define vl vector<long long>
#define mod 1000000007
#define MAX 10000001
using namespace std;
void solve();
int main(){
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t=1;
// cin>>t;
while(t--){
solve();
}
return 0;
}
string keypadCodes[] ={".;","abc", "def" ,"ghi","jkl","mno","pqrs","tu","vwx","yz"} ;
#define ppp pair<int,pair<int,int > >
void solve(){
int n;
cin>>n;
vector<int> odd;
vector<int>even;
ll sum = 0;
while(n--){
int x;
cin>>x;
sum+=x;
if(x%2==0){
even.pb(x);
}
else{
odd.pb(x);
}
}
if(odd.size()==even.size() || abs((int)odd.size()-(int)even.size())==1){
cout<<"0\n";
}else{
sort(odd.rbegin(),odd.rend());
sort(even.rbegin(),even.rend());
int k = min((int)odd.size(),(int)even.size());
int temp = k;
for(int x:odd){
if(temp==0){
break;
}
sum-=x;
temp--;
}
temp =k;
for(int x:even){
if(temp==0){
break;
}
sum-=x;
temp--;
}
if(odd.size()>even.size()){
sum-=odd[k];
}else{
sum-=even[k];
}
cout<<sum<<"\n";
}
}