-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtower.cpp
More file actions
29 lines (25 loc) · 717 Bytes
/
Copy pathtower.cpp
File metadata and controls
29 lines (25 loc) · 717 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mxN = 2e5;
vector<int> tw;
int main(int argc, char **argv) {
ios::sync_with_stdio(false);
int n, k, unq = 0, ans = 0;
cin >> n;
// find the longest non-decreasing sequence
// insert element into vector if the sequence is increasing
// else replace the iterator->element with curr
// final output is the size of the vector
for (int i = 0; i < n; i++) {
cin >> k;
int it = upper_bound(tw.begin(), tw.end(), k) - tw.begin();
if (it < tw.size()) {
tw[it] = k;
} else {
tw.push_back(k);
}
}
cout << tw.size() << "\n";
return 0;
}