Cod sursa(job #3139633)

Utilizator RolandPetreanPetrean Roland RolandPetrean Data 30 iunie 2023 13:38:32
Problema Orase Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.51 kb
// https://www.infoarena.ro/problema/orase
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'

ifstream fin("orase.in");
ofstream fout("orase.out");

#define int long long

signed main() {
  int n, m;
  fin>>m>>n;

  vector<pair<int,int>> o(n);
  for (int i=0; i<n; ++i) fin>>o[i].first>>o[i].second;
  sort(o.begin(), o.end());

  int maxx=INT_MIN, ans=0;
  for (int i=0; i<n; ++i) {
    ans = max(ans, o[i].first + o[i].second + maxx);
    maxx = max(maxx, o[i].second - o[i].first);
  }

  fout<<ans;
}