Pagini recente » Cod sursa (job #714732) | Cod sursa (job #3243088) | Cod sursa (job #2283112) | Cod sursa (job #2563850) | Cod sursa (job #2324089)
#include <fstream>
using namespace std;
ifstream f("subsir2.in");
ofstream g("subsir2.out");
int nrs;
struct pozitie
{
int val,poz;
};
pozitie vf[5001], z;
int CautBin(pozitie x)
{
int p = 1, u = nrs, poz = -1;
while(p <= u)
{
int m = (p + u) / 2;
if(x.val < vf[m].val)
{
poz = m;
u = m - 1;
}
else
p = m + 1;
}
return poz;
}
int main()
{
int n;
f >> n >> z.val;
z.poz = 1;
nrs = 1;
vf[nrs] = z;
for(int i = 2; i <= n; i++)
{
f >> z.val;
z.poz = i;
if(z.val >= vf[nrs].val)
vf[++nrs] =z;
else
{
int j = CautBin(z);
vf[j] = z;
}
}
g << nrs << '\n';
for(int i = 1; i <= nrs; i++)
g << vf[i].poz << ' ';
return 0;
}