Pagini recente » Cod sursa (job #2765427) | Cod sursa (job #696496) | Cod sursa (job #508821) | Cod sursa (job #360440) | Cod sursa (job #2333881)
#include <fstream>
#include <iostream>
#define MAX 100001
using namespace std;
int v[MAX], T[MAX];
int main()
{
int n, i, j,st, dr, mij, length = 0, gasit;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
fin >> n;
for(i = 1; i <= n; i++)
fin >> v[i];
length = 1;
T[1] = 1;
for(i = 2; i <= n; i++)
{
st = 1;
dr = length;
gasit = -1;
while(st <= dr)
{
mij = (st + dr) / 2;
if(v[i] < v[T[mij]])
{
gasit = mij;
dr = mij - 1;
}
else st = mij + 1;
}
if(gasit == -1)
{
length++;
T[length] = i;
}
else T[gasit] = i;
}
//for(i = 1; i <= length; i++)cout << T[i] << " ";
fout << length;
fin.close();
fout.close();
return 0;
}