Cod sursa(job #530198)

Utilizator rares192Preda Rares Mihai rares192 Data 7 februarie 2011 10:47:47
Problema Orase Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include<fstream>
#include<algorithm>
#include<vector>
using namespace std;

vector<pair<int, int> > a;
int n, m;

void read();
void solve();

int main()
{
	read();
	solve();
	return 0;
}

void read()
{
	ifstream fin("orase.in");
	
	fin >> m >> n;
	
	int x, y;
	while(n--)
	{
		fin >> x >> y;
		a.push_back( make_pair(x, y) );
	}
	
	fin.close();
}

void solve()
{
	ofstream fout("orase.out");
	sort(a.begin(), a.end() );

	int x, l;
	x = a[0].second - a[0].first;
	
	n = (int)a.size();
	for(int i = 1; i < n; ++i)
	{
		l = a[i].first + a[i].second + x;
		x = max( x, a[i].second - a[i].first);
	}
	
	fout << l;
	fout.close();
}