My issue
//The logic of the code is correct but i am getting correct answer only when I am not pushing the mo[i] by multiplying it with h first but instead multiply with h in the while loop while comparing
My code
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--)
{
long long n,m,h;
cin>>n>>m>>h;
vector<long long>no,mo;
long long ans = 0;
for(int i =0;i<n;i++)
{
int a;
cin>>a;
no.push_back(a);
}
for(int i =0;i<m;i++)
{
int a;
cin>>a;
a= a*h;
mo.push_back(a);
}
sort(no.begin(),no.end(),greater<int>());
sort(mo.begin(),mo.end(),greater<int>());
int i = 0;
int j = 0;
while(i<n && j<m)
{
if(no[i]>= mo[j] )
{
ans = ans + mo[j];
}else if(mo[j]>no[i] )
{
ans = ans + no[i];
}
i++;
j++;
}
cout<<ans<<endl;
}
return 0;
}
Problem Link: MOONSOON Problem - CodeChef