Pagini recente » Cod sursa (job #2372469) | Cod sursa (job #2416105) | Cod sursa (job #2271622) | Cod sursa (job #1822690) | Cod sursa (job #68906)
Cod sursa(job #68906)
#include <stdio.h>
#include <algorithm>
#define NMAX 50000
using namespace std;
typedef struct oras
{
int d;
int l;
};
oras a[NMAX+5];
int n, m;
void read()
{
int i;
scanf("%d %d", &m, &n);
for(i = 1; i <= n; ++i)
scanf("%d %d", &a[i].d, &a[i].l);
}
bool comp(const oras& x, const oras& y)
{
return (x.d < y.d|| (x.d == y.d && x.l < y.l));
}
int main()
{
int j, crt, max = -1;
freopen("orase.in", "r", stdin);
freopen("orase.out", "w", stdout);
read();
sort(a+1, a+n+1, comp);
for(crt = 1, j = 2; j <= n; ++j)
{
//printf("%d\n", crt);
if(a[j].d + a[j].l - a[crt].d + a[crt].l > max)
max = a[j].d + a[j].l - a[crt].d + a[crt].l;
if(a[j].l-a[j].d > a[crt].l-a[crt].d)
crt = j;
}
printf("%d\n", max);
//for(int i = 1; i <= n; ++i)
// printf("%d %d\n", a[i].d, a[i].l);
return 0;
}