Cod sursa(job #657114)

Utilizator okros_alexandruOkros Alexandru okros_alexandru Data 5 ianuarie 2012 19:54:18
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;
vector <pair <int,int> > v;
int n,sol;
void resolve() {
	int st,dr;
	for(st=0,dr=1;dr<n;dr++) {
		sol=max(sol,v[st].second+v[dr].second+v[dr].first-v[st].first);
		if(v[dr].second>v[st].second+v[dr].first-v[st].first)
			st=dr;
		}
}
void citire() {
	int i,m,x,y;
	ifstream in("orase.in");
	in>>m>>n;
	for(i=0;i<n;i++) {
		in>>x>>y;
		v.push_back(make_pair(x,y));
		}
}
void afis() {
	ofstream out("orase.out");
	out<<sol<<'\n';
	out.close();
}	
int main() {
	citire();
	sort(v.begin(),v.end());
	resolve();
	afis();
	return 0;
}