Pagini recente » Cod sursa (job #3262565) | Cod sursa (job #2819306) | Cod sursa (job #1273357) | Cod sursa (job #2293386) | Cod sursa (job #275230)
Cod sursa(job #275230)
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#define sFin "orase.in"
#define sFout "orase.out"
#define nMax 1000069
#define abs(x) (x<0?-1*x:x)
#define s(x) (x[0]+x[1])
using namespace std;
typedef struct {
int d, l;
} oras;
oras heap[nMax];
vector<oras> imperiu;
int n,m,heapSize;
oras newOras(int x, int y){
oras rez;
rez.d = x;
rez.l = y;
return rez;
}
int operator<(oras a, oras b){
return a.d < b.d;
}
void push(oras x){
heapSize ++;
heap[heapSize] = x;
int it = heapSize, padre = it >> 1;
while (padre > 0 && heap[it]<heap[padre]){
swap(heap[it], heap[padre]);
it = padre;
padre = it >> 1;
}
}
void mainLoop(){
ifstream fin(sFin);
ofstream fout(sFout);
fin >> m >> n;
int sol = -1*int(2e9);
for (int i=0;i<n;i++){
int x, y;
fin >> x >> y;
imperiu.push_back(newOras(x,y));
//push(newOras(x,y));
}
sort(imperiu.begin(),imperiu.end());
int min = -1 * int(2e9), max = -1*int(2e9), sum = 0;
for (int i=0;i<n;i++)
if (imperiu[i].l - imperiu[i].d > min)
min = imperiu[i].l - imperiu[i].d;
else
if (imperiu[i].d + imperiu[i].l + min > max)
max = imperiu[i].d + imperiu[i].l + min;
fout << max << "\n";
fout.close(), fin.close();
}
int main(){
mainLoop();
return 0;
}