Skip to content

Instantly share code, notes, and snippets.

@kooooohe
Last active June 14, 2021 05:48
Show Gist options
  • Save kooooohe/8cc33e0f1eb035b878db003b0779a71b to your computer and use it in GitHub Desktop.
Save kooooohe/8cc33e0f1eb035b878db003b0779a71b to your computer and use it in GitHub Desktop.
blog-binary_search_2
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<long long> a(N);
vector<long long> b(N);
vector<long long> r(N * N);
for (int i = 0; i < N; ++i) {
cin >> a[i];
}
for (int i = 0; i < N; ++i) {
cin >> b[i];
}
int ind = 0;
// O(N)
for (int i = 0; i < N; ++i) {
// O(N)
for (int j = 0; j < N; ++j) {
r[ind] = a[i] * b[j];
ind++;
}
}
// O(log_N^2)
sort(r.begin(), r.end());
cout << r[M-1] << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment