Cod sursa(job #3252906)

Utilizator Vlad_NistorNIstor Vlad Vlad_Nistor Data 31 octombrie 2024 14:35:12
Problema Subsir crescator maximal Scor 65
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.76 kb
#include <bits/stdc++.h>
using namespace std;

vector<int> LIS(vector<int>& nums){
    vector<int> ans;
    ans.push_back(nums[0]);
    for(auto x : nums) {
        if(x > ans.back()) {
            /// we can go forward with the solution
            ans.push_back(x);
        }else {
            int first = lower_bound(ans.begin(), ans.end(), x) - ans.begin();
            ans[first] = x;
        }
    }
    return ans;
}

int32_t main(void){
    ofstream cout("scmax.out");
    ifstream cin("scmax.in");
    vector<int> nums;
    int n;
    cin >> n;
    for(int i = 1;i <= n;i++) {
        int x;
        cin >> x;
        nums.push_back(x);
    }
    vector<int> ans =LIS(nums);
    cout << ans.size() << '\n';
    for(auto it : ans) {
        cout << it << ' ';
    }
}