Cod sursa(job #125294)

Utilizator gabitzish1Gabriel Bitis gabitzish1 Data 20 ianuarie 2008 12:25:42
Problema Stergeri Scor 0
Compilator cpp Status done
Runda preONI 2008, Runda 3, Clasele 5-8 Marime 0.54 kb
#include <stdio.h>

long v[2000002], n, m, k, p, s, x, y;

 
void update()
    {
     if(x<=k)
       {
        if(y<=k) s+=(y-x+1)+p,p=0;
        else
          {
           p+=y-k;
           s=s+(k-x+1)+p;
           p=0;
          }
        }
     else p+=y-x+1;
    }

int main()
{
	freopen("stergeri.in","r",stdin);
	freopen("stergeri.out","w",stdout);

	int j;
	scanf("%d %d %d", &n, &m, &k);
	s = k;

	for (j = 1; j <= m; j++)
	{
		scanf("%d %d", &x, &y);
		update();
	}

	printf("%d\n",s);
	return 0;
}