My issue
how to approach this problem on python
My code
# cook your dish here
t = int(input())
for _ in range(t):
n , m = map(int , input().split())
a = list(map(int , input().split()))
b = list(map(int , input().split()))
a1 = sum(a)
b1 = sum(b)
if a1 > b1:
Problem Link: Fair Elections Practice Coding Problem - CodeChef
@macasual744
here ,bro plzz refer my c++ code for better understanding of the logic
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
int a[n],b[m];
int sm=0,sm1=0;
for(int i=0;i<n;i++)
{
cin>>a[i];
sm+=a[i];
}
for(int i=0;i<m;i++)
{
cin>>b[i];
sm1+=b[i];
}
sort(a,a+n);
sort(b,b+m);
if(sm>sm1)
cout<<0;
else
{
int cnt=0;
int fnd=0;
for(int i=0,j=m-1;i<n&&j>=0;j--,i++)
{
sm-=a[i];
sm+=b[j];
sm1-=b[j];
sm1+=a[i];
cnt++;
if(sm>sm1)
{
cout<<cnt;
fnd=1;
break;
}
}
if(!fnd)
cout<<-1;
}
cout<<endl;
}
}
Thank you very much though Im very late to say this I appreciate that