It is outputting 17 instead of 19.IDK why
What my code does is, it first sorts both the arrays and then checks which has the book with the largest height and swaps the book with largest height (in the other array) with the book which has the smallest height.
Here is my code
#include <iostream>#include <bits/stdc++.h>using namespace std;void swap(int* a, int* b){int t = *a;*a = *b;*b = t;}int main() {int n;int k;cin >> n >> k;int arr1[n],arr2[n];for (int s = 0; s < n;s++) cin >> arr1[s];for (int f = 0; f < n;f++) cin >> arr2[f];for (int w = k; w >= 0; w--){int i = 0;int j = n - 1;sort (arr1 , arr1 + n);sort (arr2 , arr2 + n);if (arr1[n-1] > arr2[n-1]) {swap (&arr2[j],&arr1[i]);}if (arr2[n-1] > arr1[n-1]){swap (&arr1[j],&arr2[i]);}}sort (arr1 , arr1 + n);sort (arr2 , arr2 + n);cout << "" << arr1[n-1] + arr2[n-1];return 0;}