-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1144B.cpp
More file actions
65 lines (59 loc) · 966 Bytes
/
Copy path1144B.cpp
File metadata and controls
65 lines (59 loc) · 966 Bytes
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
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
int main()
{
int n;
cin >> n;
lli sum=0,sum1=0,sum2=0;
vector<lli> a(n),b,c;
for(int i=0;i<n;i++)
{
cin >> a[i];
if(a[i]%2 == 0)
b.push_back(a[i]);
else
c.push_back(a[i]);
sum += a[i];
}
sort(b.begin(),b.end(),greater<int>());
sort(c.begin(),c.end(),greater<int>());
lli i=0,j=0,k=1;
sum1 = sum;
while(true)
{
if(k and i<b.size())
{
sum1 -= b[i];
i++;
}
else if(!k and j<c.size())
{
sum1-= c[j];
j++;
}
else
break;
k = 1-k;
}
i=0,j=0,k=0;
sum2 = sum;
while(true)
{
if(k and i<b.size())
{
sum2 -= b[i];
i++;
}
else if(!k and j<c.size())
{
sum2-= c[j];
j++;
}
else
break;
k = 1-k;
}
cout << min(sum2,sum1) << endl;
return 0;
}