Pagini recente » Cod sursa (job #1597704) | Cod sursa (job #3290292) | Cod sursa (job #1431283) | Cod sursa (job #1608280) | Cod sursa (job #2134806)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int n,V[100005],i,lgc,j;
bool ok;
int Q[100005];
bool CautBin(int);
int main()
{
fin>>n;
for (i=1;i<=n;i++)
fin>>V[i];
for (i=1;i<=n;i++)
{
if (!CautBin(i))
{
lgc++;
Q[lgc]=V[i];
}
}
fout<<n-lgc;
return 0;
}
bool CautBin(int x)
{
int st,sf,mij,poz1;
st=1;
sf=lgc;
poz1=0;
mij=(st+sf)/2;
while (st<=sf)
{
if (Q[mij]>V[x])
{
poz1=mij;
sf=mij-1;
}
else
st=mij+1;
mij=(st+sf)/2;
}
if (poz1==0)
return 0;
else
{
Q[poz1]=V[x];
return 1;
}
}