Pagini recente » Profil M@2Te4i | Cod sursa (job #460938)
Cod sursa(job #460938)
#include <iostream>
#include <fstream>
#define INFILE "orase.in"
#define OUTFILE "orase.out"
#define max_N 51000
using namespace std;
ifstream fin(INFILE);
ofstream fout(OUTFILE);
long int M, N, D[max_N], L[max_N], maxim1, maxim2, i, poz;
int main()
{
fin >> M >> N;
for(i = 1; i <= N; i ++)
{
fin >> D[i] >> L[i];
D[i] = D[i] * 100 + L[i];
}
sort(D + 1, D + N + 1);
for(i = 1; i <= N; i ++)
{
L[i] = D[i] % 100;
D[i] = D[i] / 100;
}
for(i = 1; i <= N; i ++)
{
if(L[i] - D[i] > maxim1)
{
maxim1 = L[i] - D[i];
poz = i;
}
if(L[i] + D[i] > maxim2 && i > poz)
maxim2 = L[i] + D[i];
}
fout << maxim1 + maxim2;
return 0;
}