-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathE.cpp
101 lines (100 loc) · 2.34 KB
/
E.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
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()
{
fastio;
long long x,y,a,b,c,i,t,p=0,q=0,r=0;
vector<pair<long long,long long> > apples;
cin>>x>>y>>a>>b>>c;
for(i=0;i<a;i++)
{
cin>>t;
apples.push_back(make_pair(t,0LL));
}
for(i=0;i<b;i++)
{
cin>>t;
apples.push_back(make_pair(t,1LL));
}
for(i=0;i<c;i++)
{
cin>>t;
apples.push_back(make_pair(t,2LL));
}
sort(apples.begin(),apples.end(),greater<>());
/*for(i=0;i<apples.size();i++)
cout<<apples[i].first<<" "<<apples[i].second<<"\n";*/
vector<long long> vect;
for(i=0;i<x+y;i++)
{
if(apples[i].second==0){
p++;
if(p<=x)
vect.push_back(apples[i].first);
}
else if(apples[i].second==1){
q++;
if(q<=y)
vect.push_back(apples[i].first);
}
else
r++;
}
if(r>=x-min(p,x)+y-min(q,y))
{
for(i=0;i<x+y;i++)
{
if(r==0)
break;
else if(apples[i].second==2)
{
vect.push_back(apples[i].first);
r--;
}
}
}
else
{
long long temp=x-min(p,x)+y-min(q,y)-r;
for(i=x+y;i<apples.size();i++)
{
if(temp==0)
break;
if(apples[i].second==0 && p<x)
{
vect.push_back(apples[i].first);
p++;
temp--;
}
if(apples[i].second==1 && q<y)
{
vect.push_back(apples[i].first);
q++;
temp--;
}
}
int g=0;
for(i=x+y;i<apples.size();i++)
{
if(apples[i].second==2 && apples[i].first>vect[vect.size()-1-g])
{
vect.erase(vect.begin()+vect.size()-1-g);
vect.push_back(apples[i].first);
g++;
}
}
for(i=0;i<x+y;i++)
{
if(apples[i].second==2)
vect.push_back(apples[i].first);
}
}
long long ans=0LL;
for(i=0;i<vect.size();i++){
//cout<<vect[i]<<" ";
ans+=vect[i];
}
cout<<ans<<"\n";
return 0;
}