Pagini recente » Cod sursa (job #176472) | Cod sursa (job #571895) | Cod sursa (job #1504590) | Cod sursa (job #2601514) | Cod sursa (job #125438)
Cod sursa(job #125438)
#include <stdio.h>
int max=0;
int n,m,k,rsp,q=0; //!!!!! ATENTIE lA 0 !! VAAACOOO !! (Made by `GhOsT`)(CS name)
unsigned char a[20002];
int BS(int st,int dr,int V)
{
int m;
if (st>dr) return -1; else
{
m=(st+dr)/2;
if (V==a[m]) return m;
else if (V<a[m]) return BS(st,m-1,V); else return BS(m+1,dr,V);
}
}
void fatotul(int x,int y)
{
if (q!=0)
{
int rasp1;
rasp1=BS(1,q*2,x);
if (rasp1!=-1)
{
fatotul(a[rasp1+1]+1,a[rasp1+1]+1+y-x);
} else {a[2*(++q)]=y;a[2*q-1]=x;}
} else {a[2*(++q)]=y;a[2*q-1]=x;}
}
void citeste()
{
scanf("%d %d %d",&n,&m,&k);
int x=0,y=0,i=0;
for (i=1;i<=m;i++)
{
scanf("%d %d",&x,&y);
fatotul(x,y);
}
for (i=1;i<=q*2;i++) if (max<a[i]) max=a[i];
rsp=max+k;
}
int main()
{
freopen("stergeri.in","r",stdin);
freopen("stergeri.out","w",stdout);
citeste();
printf("%d",rsp);
return 0;
}