Cod sursa(job #1589784)

Utilizator antanaAntonia Boca antana Data 4 februarie 2016 13:47:56
Problema Orase Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <cstdio>
#include<algorithm>
#define MAX 50000
using namespace std;
struct orase{long long x, y;};
orase v[MAX+2];
long long best[MAX+2], maxi;
inline long long maxim(long long a, long long b)
{
    if(a>b)
        return a;
    return b;
}
bool cresc(orase a, orase b)
{
    if(a.x<b.x)
        return true;
    if(a.x==b.x)
        return (a.y<b.y);
    return false;
}
inline long long dist(int i, int j){
    return v[i].y+v[j].y+v[j].x-v[i].x;
}
int main()
{
    freopen("orase.in", "r", stdin);
    freopen("orase.out", "w", stdout);
    int n, i, m;
    scanf("%d%d", &n, &m);
    for(i=1;i<=n;i++)
        scanf("%lld%lld", &v[i].x, &v[i].y);
    sort(v+1, v+n+1, cresc);
    best[1]=0;
    best[2]=dist(1, 2);
    maxi=best[2];
    for(i=3;i<=n;i++)
    {
        best[i]=maxim(best[i-1]-v[i-1].y+v[i].y+v[i].x-v[i-1].x, dist(i-1, i));
        maxi=maxim(maxi, best[i]);
    }
    printf("%lld", maxi);
    return 0;
}