Cod sursa(job #2813105)

Utilizator andreic06Andrei Calota andreic06 Data 5 decembrie 2021 19:07:31
Problema Orase Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <iostream>
#include <fstream>
#include <algorithm>

using namespace std;
const int NMAX = 5e5;
pair<int, int> point[1 + NMAX];

ifstream fin ( "orase.in" );
ofstream fout ( "orase.out" );
int main()
{
   int m, n; fin >> m >> n;
   for ( int i = 1; i <= n; i ++ )
      fin >> point[i].first >> point[i].second;
   sort ( point + 1, point + n + 1 );

   int max_cost = 0; int max_delete = 0;
   int answer = 0;
   for ( int i = 1; i <= n; i ++ ) {
      max_cost = max ( max_cost, point[i].first + point[i].second );
      answer = max ( answer, max_cost + max_delete );
      max_delete = max ( max_delete, point[i].second - point[i].first );
   }
   fout << answer;
    return 0;
}