Pagini recente » Cod sursa (job #556211) | Cod sursa (job #288327) | Cod sursa (job #324943) | Cod sursa (job #3225025) | Cod sursa (job #1648289)
#include <fstream>
#define DMAX 100002
using namespace std;
typedef long long ll;
ifstream in("scmax.in");
ofstream out("scmax.out");
int n, lung_max, poz;
int before[DMAX], temp[DMAX];
ll v[DMAX];
void afisare(int ind){
if(before[ind])
afisare(before[ind]);
out<<v[ind]<<" ";
}
int loc_poz(ll val){
int l = 1, r = lung_max, mij;
while(l <= r){
mij = (l+r)/2;
if(val > v[temp[mij]] && val <= v[temp[mij+1]])
return mij;
if(v[temp[mij]] >= val)
r = mij -1;
if(v[temp[mij + 1]] < val)
l = mij +1;
}
return r;
}
int main()
{
in>>n;
for(int i = 1; i <= n; ++i){
in>>v[i];
}
temp[1] = 1;
lung_max = 1;
for(int i = 2; i <= n; ++i){
poz = loc_poz(v[i]);
temp[++poz] = i;
before[i] = temp[poz - 1];
lung_max = (poz > lung_max) ? poz : lung_max;
}
out<<lung_max<<"\n";
afisare(temp[lung_max]);
out<<"\n";
in.close();
out.close();
return 0;
}