Cod sursa(job #275230)

Utilizator recviemAlexandru Pana recviem Data 10 martie 2009 12:27:35
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.24 kb
#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;
}