题解 | #查找#

查找

https://www.nowcoder.com/practice/8e0c0e8c78944847be9bca54b59d713f

#include<bits/stdc++.h>
using namespace std;
int main() {
    set<int>s;
    //write your code here......
    int m, n;
    cin >> n >> m;
    vector<int>v;
    for (int i = 0; i < n; i++) {
        int num = 0;
        cin >> num;
        s.insert(num);
    }
    for (int i = 0; i < m; ++i) {
        int x;
        cin >> x;
        auto it = s.upper_bound(x);
        if (it == s.end()) {
            cout << -1 << endl;
        } else {
            cout << *it << endl;
        }
    }
    return 0;
}


全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务