Cod sursa(job #2629920)

Utilizator segtreapMihnea Andreescu segtreap Data 23 iunie 2020 12:01:05
Problema Orase Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;
const int N = 50000 + 7;
int n;

struct T {
  int x;
  int l;
};

bool operator < (T f, T s) {
  return f.x < s.x;
}

T a[N];

int main() {
  freopen ("orase.in", "r", stdin);
  freopen ("orase.out", "w", stdout);
  scanf("%d %d", &n, &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &i[a].x, &i[a].l);
  }
  sort(a + 1, a + n + 1);
  int so = -(int) 1e9, mx = -(int) 1e9;
  for (int i = 1; i <= n; i++) {
    so = max(so, mx + a[i].x + a[i].l);
    mx = max(mx, a[i].l - a[i].x);
  }
  cout << so << "\n";
  return 0;
}