Pagini recente » Cod sursa (job #2290648) | Cod sursa (job #2022160) | Cod sursa (job #1712063) | Cod sursa (job #1020487) | Cod sursa (job #442921)
Cod sursa(job #442921)
#include <cstdio>
#include <algorithm>
using namespace std;
#define MAX 50005
#define hg 8192
#define IN "orase.in"
#define OUT "orase.out"
struct vector
{
int D,L;
}V[MAX],maxi;
struct comp
{
bool operator () (const vector& lhs , const vector& rhs)
{
if (lhs.D == rhs.D)
return lhs.L < rhs.L;
return lhs.D < rhs.D;
}
};
int M, N, i, rez, poz;
char ch[hg];
inline void cit (int &x)
{
x = 0;
if (ch[0]=='\0') fread (ch, 1, hg, stdin);
else while (ch[poz] < '0' || ch[poz] > '9')
if (++poz == hg)
fread (ch, 1, hg, stdin), poz = 0;
while (ch[poz] >= '0' && ch[poz] <= '9')
{
x = x * 10 + ch[poz] - '0';
if (++poz == hg)
fread (ch, 1, hg, stdin), poz = 0;
}
}
int main()
{
freopen(IN,"r",stdin);
freopen(OUT,"w",stdout);
cit(M), cit(N);
for (i = 1; i <= N; i++)
cit(V[i].D), cit(V[i].L);
sort(V + 1, V + N + 1, comp());
maxi.D = V[1].D, maxi.L = V[1].L;
for (i = 2; i <= N; i++)
{
int part = V[i].L + V[i].D + maxi.L - maxi.D;
if (part > rez) rez = part;
if (V[i].L - V[i].D > maxi.L - maxi.D) maxi.L = V[i].L, maxi.D = V[i].D;
}
printf("%d",rez);
return 0;
}