L2-014 列车调度

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> v(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> v[i];
    }    
    
    vector<int> res; 
    for (int i = 1; i <= n; i++) {
        int x = v[i];
        int sz = res.size();
        int idx = lower_bound(res.begin(), res.end(), x) - res.begin();
        if (idx == sz) res.push_back(x);
        else {
            res[idx] = x;
        }
    }

    cout << res.size() << "\n";
    
    return 0;
}

posted @ 2022-03-17 20:42  Xxaj5  阅读(56)  评论(0编辑  收藏  举报