Cod sursa(job #2919517)
Utilizator | Data | 17 august 2022 21:20:48 | |
---|---|---|---|
Problema | Subsir crescator maximal | Scor | 55 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.51 kb |
#include <bits/stdc++.h>
#define N 100005
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int n,a[N],best[N],p;
///best[i]=capatul minim unui subsir crescator de lg i
int main()
{
int i,j,poz,lgmax;
fin>>n;
for(i=1;i<=n;i++) fin>>a[i];
best[p=1]=a[1];
for(i=2;i<=n;i++)
if(a[i]>best[p]) best[++p]=a[i];
else best[upper_bound(best+1,best+p+1,a[i])-best]=a[i];
fout<<p<<"\n";
for(i=1;i<=p;i++) fout<<best[i]<<" ";
return 0;
}