cses

My solution for the coding challenges of cses.fi
git clone https://git.tronto.net/cses
Download | Log | Files | Refs | README

towers_1063.cpp (324B)


      1 #include <algorithm>
      2 #include <iostream>
      3 #include <vector>
      4 
      5 int main() {
      6 	size_t n;
      7 	std::cin >> n;
      8 	std::vector<int> v;
      9 	for (size_t i = 0; i < n; i++) {
     10 		int x;
     11 		std::cin >> x;
     12 		auto it = std::upper_bound(v.begin(), v.end(), x);
     13 		if (it == v.end()) v.push_back(x);
     14 		else *it = x;
     15 	}
     16 	std::cout << v.size() << "\n";
     17 }