Cod sursa(job #1477747)

Utilizator AlexandraaaaMereu Alexandra Alexandraaaa Data 26 august 2015 20:46:45
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

bool cmp(pair<int, int> a, pair <int, int> b){
	return a.first < b.first;
}

int main(){
	ifstream f("orase.in");
	ofstream g("orase.out");

	int n, m, i, j, x, y, s;
	vector <pair <int, int> > a;
	f >> m >> n;
	for (i = 0; i < n; ++i){
		f >> x >> y;
		a.push_back(make_pair(x, y));
	}
	sort(a.begin(), a.end(), cmp);

	i = s =0;
	for (j = 1; j < n; ++j){
		x = a[j].first + a[j].second + a[i].second-a[i].first;
		if (a[j].second > x - a[j].second)i = j;
		if (s < x)s = x;
	}
	g << s;
	

	f.close();
	g.close();

	return 0;
}