-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrain.cpp
More file actions
32 lines (28 loc) · 714 Bytes
/
Copy pathtrain.cpp
File metadata and controls
32 lines (28 loc) · 714 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
30
31
32
#include <cstdio>
#include <vector>
#include <algorithm>
#define MAXN 10010
using namespace std;
int input[MAXN];
vector <int> best;
vector <int> lis;
int main(){
int n, aux;
scanf("%d", &n);
for(int i = 1; i <= n; ++i) scanf("%d", &input[i]);
for(int i = 1; i <= n; ++i){
aux = input[i];
if(!best.size()) best.push_back(aux);
if(aux > best.back()){
best.push_back(aux);
lis.push_back(best[best.size() - 2]);
}
else
*lower_bound(best.begin(), best.end(), aux) = aux;
}
lis.push_back(best.back());
printf("%d\n", (int)best.size());
for(int i = 0; i < lis.size(); ++i) printf("%d ", lis[i]);
printf("\n");
return 0;
}