AtCoder Beginner Contest 134-E - Sequence Decomposing

(https://atcoder.jp/contests/abc134/tasks/abc134_e)

 

 Meaning of the questions: find the longest sequence smallest increase in the number of

Ideas: finding the smallest increase in the number of the longest sequence, only need to find the smallest increase in the last element of each sequence, then the number of elements and is the longest sequence of the smallest rise in the number of

#include <iostream>
#include<set>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn =1e5+10;
int a[maxn];
multiset<int> q;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i];
    for(int i=1;i<=n;i++)
    {
        multiset<int>:: iterator it =q.lower_bound(a[i]);
        if(it==q.begin())
            q.insert(a[i]);
        else
        {
            it--;
            q.erase(it);
            q.insert(a[i]);
        }
    }
    cout << q.size();
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/wjc2021/p/11220483.html