Hãy luôn nhớ cảm ơn và vote 5*
nếu câu trả lời hữu ích nhé!
$\color{#1fdb91}{\texttt{C}}\color{#0aaec9}{\texttt{+}}\color{#e9418e}{\texttt{+}}$
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int n, m, tmp; cin >> n >> m;
multiset<int> s;
for (int i=1; i<=n; ++i) {
cin >> tmp;
s.insert(tmp);
}
for (int i=1; i<=m; ++i) {
cin >> tmp;
if (s.empty()) {cout << "-1\n"; continue;}
auto res = s.lower_bound(tmp);
if (res == s.end()) -- res;
while (*res > tmp && res != s.begin()) -- res;
if (res == s.begin() && *res > tmp) {
cout << "-1\n";
} else {
cout << *res << '\n';
s.erase(res);
}
}
}
$\\$
\begin{array}{c|c|c}\color{#ffd710}{\texttt{\{}} \color{#8655d6}{\texttt{\{}}\ \ \color{#8cdcda}{\text{Daoanhviet96}}\ \ \color{#8655d6}{\texttt{\}}} \color{#ffd710}{\texttt{\}}}\end{array}
Hãy giúp mọi người biết câu trả lời này thế nào?
Bảng tin