Last active
June 14, 2021 05:48
-
-
Save 0xkohe/8cc33e0f1eb035b878db003b0779a71b to your computer and use it in GitHub Desktop.
blog-binary_search_2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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