You are given two arrays and , both of length .
You would like to choose exactly distinct indices such that is maximized. Find this maximum value.
Input Format
- The first line of input contains a single integer , denoting the number of test cases. The description of test cases follows.
- Each test case consists of lines of input.
- The first line of each test case contains two space-separated integers and .
- The second line contains space-separated integers denoting the elements of .
- The third line contains space-separated integers denoting the elements of .
Output Format
For each test case, output a new line containing one integer — the required maximum value.
Constraints
Sample Input 1
3
5 3
4 2 3 1 4
3 2 5 5 1
4 2
1 2 3 4
4 3 2 1
6 3
8 10 3 6 7 2
4 8 4 1 1 6
Sample Output 1
9
5
18
Explanation
Test Case : One optimal choice of indices is . This gives and .
Test Case : One optimal choice of indices is .
Test Case : One optimal choice of indices is .
Solution:
#include <iostream>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--){
int n,k,max=0;
cin>>n>>k;
int a[n],b[n];
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
cin>>b[i];
}
int sum1=0,sum2=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
max=(a[i],b[i]);
sum1+=a[i];
sum2+=b[i];
}
}
if(sum1>sum2){
cout<<sum1<<endl;
}else{
cout<<sum2<<endl;
}
}
return 0;
}
No comments:
Post a Comment