Cod sursa(job #275238)

Utilizator recviemAlexandru Pana recviem Data 10 martie 2009 12:29:42
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>

#define sFin "orase.in"
#define sFout "orase.out"
#define nMax 1000069

using namespace std;

typedef struct {
	int d, l;
} oras;

vector<oras> imperiu;

int n,m;

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 mainLoop(){
	ifstream fin(sFin);
	ofstream fout(sFout);

	fin >> m >> n;

	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);

	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;
}