Untitled
unknown
c_cpp
10 months ago
866 B
5
Indexable
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
int k;
cin >> n >> k;
vector<int> a(n), b(n);
for (auto &x : a) cin >> x;
for (auto &x : b) cin >> x;
set<int> options(a.begin(), a.end());
options.insert(b.begin(), b.end());
sort(a.begin(), a.end());
sort(b.begin(), b.end());
int answer = 0;
for (int x : options) {
int A = n - (lower_bound(a.begin(), a.end(), x) - a.begin());
int B = n - (lower_bound(b.begin(), b.end(), x) - b.begin());
if (B - A <= k) {
answer = max(answer, x * B);
}
}
cout << answer << "\n";
}
}
Editor is loading...
Leave a Comment