Cod sursa(job #1959247)

Utilizator AlexandruLuchianov1Alex Luchianov AlexandruLuchianov1 Data 9 aprilie 2017 11:36:06
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <iostream>
#include <fstream>
#include <algorithm>

using namespace std;
ifstream in ("orase.in");
ofstream out ("orase.out");

int const nmax = 50000;

struct turn{
  int h ;
  int x;
  bool operator < (turn a) const{
    return x < a.x;
  }
  bool operator == (turn a) const{
    return x == a.x;
  }
};
turn v[1 + nmax];
int st[1 + nmax];

int main() {
  int m ,n;
  in>>m>>n;
  for(int i = 1 ; i <= n ;i++){
    in>>v[i].x>>v[i].h;
  }
  sort(v + 1,v + n + 1);
  int smax = 0;
  for(int i = 1 ; i <= n ;i++){
    st[i] = max(st[i - 1], v[i - 1].h) + v[i].x - v[i - 1].x;
    if(smax < st[i] + v[i].h)
      smax = st[i] + v[i].h;

  }
  out<<smax;
  return 0;
}