Skip to content

Instantly share code, notes, and snippets.

@lectricas
Created March 13, 2021 17:55
Show Gist options
  • Save lectricas/220e0d259607251def31b68826c0b988 to your computer and use it in GitHub Desktop.
Save lectricas/220e0d259607251def31b68826c0b988 to your computer and use it in GitHub Desktop.
#include <vector>
#include <iostream>
int main() {
int n, m;
std::cin >> n;
std::cin >> m;
std::vector<int> nv(n);
std::vector<int> mv(m);
for (int i = 0; i < n; i++) {
std::cin >> nv[i];
}
for (int i = 0; i < m; i++) {
std::cin >> mv[i];
}
std::vector<int> rv;
int ni = 0, mi = 0;
while (ni < n && mi < m) {
if (nv[ni] <= mv[mi]) {
rv.push_back(nv[ni]);
ni++;
} else {
rv.push_back(mv[mi]);
mi++;
}
}
while (ni < n) {
rv.push_back(nv[ni]);
ni++;
}
while (mi < m) {
rv.push_back(mv[mi]);
mi++;
}
// for (int i = 0; i < rv.size(); i++) {
// std::cout << rv[i] << " ";
// }
if (rv.size() % 2 == 0) {
double res = (rv[rv.size() / 2 - 1] + rv[rv.size() / 2]) / 2.0;
std::cout << res;
} else {
std::cout << rv[rv.size() / 2];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment