-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFAIRELCT.cpp
60 lines (60 loc) · 985 Bytes
/
FAIRELCT.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
//j2infy Codechef-Long Jan-21
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long int
using namespace std;
ll CalcSum(ll a[],ll n)
{
ll sum=0;
for(ll i=0;i<n;i++)
sum+=a[i];
return sum;
}
int main(void)
{
IOS;
int t;
cin>>t;
while(t--)
{
ll n,m;
cin>>n>>m;
ll jhon[n],jack[m];
ll sumjhon=0,sumjack=0;
for(int i=0;i<n;i++)
{
cin>>jhon[i];
sumjhon+=jhon[i];
}
for(int i=0;i<m;i++)
{
cin>>jack[i];
sumjack+=jack[i];
}
int count=0,flag=0;
if(sumjhon > sumjack) count=0;
else
{
sort(jhon,jhon+n);
sort(jack,jack+m);
int i=m-1;
count = 1;
while(count)
{
swap(jhon[(count-1)%n],jack[i]);
int jh = CalcSum(jhon,n);
int ja = CalcSum(jack,m);
i--;
if(jh > ja) break;
else if((jh<=ja)&&i==0)
{
count = -1;
break;
}
count++;
}
}
cout<<count<<"\n";
}
return 0;
}