-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFair_Elections.cpp
54 lines (47 loc) · 1.02 KB
/
Fair_Elections.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
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--)
{
int fu,ck;
cin>>fu>>ck;
int a[fu],b[ck];
int k=0,l=0;
for(int i=0;i<fu;i++)
{
cin>>a[i];
k=k+a[i];
}
for(int aman=0;aman<ck;aman++)
{
cin>>b[aman];
l = l+b[aman];
}
if(k>l)
{
cout<<"0"<<endl;
}
else {
sort(a,a+fu);
sort(b,b+ck);
reverse(b,b+ck);
int count =0;
int j = 0;
for(int i=0;i<fu;i++)
{
k = k - a[i] + b[j];
l = l - b[j] + a[i];
swap(a[i],b[j]);
count++;
j++;
if(k>l){
break;
}
}
cout<<count<<endl;
}
}
return 0;
}