My issue
I don’t know why but the problem is only with the third test case. I guess there might be issue with for loop at last. Is it a correct approach?
My code
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int T;
cin>>T;
while(T--)
{
int N,M,H;
cin>>N>>M>>H;
int A[N];
int B[H];
for(int i = 0; i < N; i++)
{
cin>>A[i];
}
for(int j = 0; j < H; j++)
{
cin>>B[j];
}
sort(A, A+N, greater<int>());
sort(B, B+H, greater<int>());
int K = min(N,M);
long long P = 0;
for(int i = 0; i < K; i++)
{
P += min(A[i], H*B[i]);
}
cout<<P<<endl;
}
return 0;
}
Learning course: Greedy Algorithms
Problem Link: EVacuate to Moon Practice Problem in Greedy Algorithms - CodeChef