Mai intai trebuie sa te autentifici.
Cod sursa(job #2355082)
| Utilizator | Data | 25 februarie 2019 20:09:54 | |
|---|---|---|---|
| Problema | Subsir crescator maximal | Scor | 60 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 1.11 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("scmax.in");
ofstream fout ("scmax.out");
inline bool compare(const int & a, const int & b)
{
return a < b;
}
const int MX = 100000 + 50;
int n, v[MX], sz;
vector <int> aux, pos;
void afisare(const int & i, const int & sz)
{
if(i<0||sz<1)
{
fout<<aux.size()<<"\n";
return;
}
if(pos[i]==sz)
{
afisare(i-1,sz-1);
fout<<v[pos[i]]<<" ";
}
else
{
afisare(i-1,sz);
}
}
int main()
{
fin >> n;
for(int i=1; i<=n; ++i)
fin >> v[i];
aux.push_back(v[1]);
pos.push_back(1);
for(int i=2;i<=n;++i)
if(v[i]>aux.back())
{
aux.push_back(v[i]);
pos.push_back(i);
}
else if(v[i]<aux.back())
{
vector <int>::iterator p=lower_bound(aux.begin(),aux.end(),v[i],compare);
*p=v[i];
int k=p-aux.begin()+1;
pos.push_back(k);
}
sz=aux.size();
afisare(pos.size()-1,sz);
return 0;
}
