Pagini recente » Cod sursa (job #3144425) | Cod sursa (job #2143778) | Cod sursa (job #1954957) | Cod sursa (job #2805112) | Cod sursa (job #68216)
Cod sursa(job #68216)
#include <cstdio>
#include <cstdlib>
#define nmax 50000
FILE *in = fopen("orase.in","r"), *out = fopen("orase.out","w");
struct orase
{
int d, l;
};
int m, n;
orase a[nmax];
int max, pozmax;
int rez;
void read()
{
fscanf(in, "%d %d", &m, &n);
for ( int i = 0; i < n; ++i )
{
fscanf(in, "%d %d", &a[i].d, &a[i].l);
if ( a[i].l > max )
max = a[i].l, pozmax = i;
}
}
int main()
{
read();
for ( int i = 0; i < n; ++i )
if ( i != pozmax )
if ( a[i].l + max + abs(a[i].d - a[pozmax].d) > rez )
rez = a[i].l + max + abs(a[i].d - a[pozmax].d);
fprintf(out, "%d\n", rez);
return 0;
}