Cod sursa(job #1216339)

Utilizator tdr_drtTdr Drt tdr_drt Data 4 august 2014 11:07:57
Problema Orase Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include<fstream>
#include<algorithm>
using namespace std;
ifstream f("orase.in ");
ofstream g("orase.out");
int n,m,i;
long long max1,max2=-1;

struct pie{
long long x;
long long y;
}querry[50001];

bool cmp(const pie &a1,const pie &a2){
return a1.x<a2.x;
}

void read(){
  f>>m>>n;
  for(int i=1;i<=n;i++)
  {
      f>>querry[i].x>>querry[i].y;
  }
}

void solve(){
   sort(querry+1,querry+n+1,cmp);
   max1=querry[1].y-querry[1].x;
   for(i=2;i<=n;i++){
       max2=max(max2,querry[i].x+querry[i].y+max1);
       max1=max(max1,querry[i].y-querry[i].x);
   }
}

void write(){
   g<<max2;
}

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