alg2025/src/8/26/P2782.cpp
2025-08-26 15:11:31 +08:00

49 lines
1.1 KiB
C++

#include <algorithm>
#include <cstdint>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <ostream>
#include <utility>
#include <vector>
using ll = int64_t;
std::ostream& operator<<(std::ostream& os, const std::pair<ll, ll>& p){
os << "{ " << p.first << ", " << p.second << " }";
return os;
}
#define pa(a)do{for(auto v:(a)){std::cout<<v<<", ";}std::cout<<"\n";}while(0)
int main(){
std::iostream::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n;
std::cin >> n;
std::vector<ll> c(n);
std::vector<std::pair<ll, ll>> input(n);
for (ll i = 0; i < n; i++){
std::cin >> input[i].first >> input[i].second;
}
std::sort(input.begin(), input.end());
for (ll i = 0; i < input.size(); i++){
c[i] = input[i].second;
}
std::vector<ll> f;
f.reserve(n);
for (ll x : c) {
auto it = std::lower_bound(f.begin(), f.end(), x);
if (it == f.end()) {
f.push_back(x);
} else {
*it = x;
}
pa(f);
}
std::cout << f.size() << std::endl;
return 0;
}