Pagini recente » Cod sursa (job #1418639) | Cod sursa (job #2847954) | Cod sursa (job #442517) | Cod sursa (job #1940910) | Cod sursa (job #2297501)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("sdo.in");
ofstream fout("sdo.out");
int n,i,k,h[3000002],x;
void sus(int nod)
{
while (nod>1 && h[nod>>1]<h[nod])
{
swap(h[nod],h[nod>>1]);
nod>>=1;
}
}
void jos(int nod)
{
int son=nod*2;
while (1)
{
if (h[son]<h[son+1]) son++;
if (h[son]>h[nod]) {swap(h[son],h[nod]); } else break;
}
}
int main()
{
fin>>n>>k;
for (i=1;i<=k;i++)
{
fin>>h[i];
sus(i);
}
for (;i<=n;i++)
{
fin>>x;
if (x<h[1])
{
h[1]=x;
jos(1);
}
}
fout<<h[1];
return 0;
}