Cod sursa(job #777809)

Utilizator anca_gheorgheGheorghe Anca Elena anca_gheorghe Data 13 august 2012 14:53:01
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <iostream>
#include <fstream>
#include <algorithm>

using namespace std;

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

struct punct
{
    int x, y;
};
punct v[50000];

bool cmp (punct a, punct b)
{
    return a.x < b.x;
}

int main()
{
    int m, n, u=1, dc, dmax=-1, i;
    in>>m>>n;
    for(i=1;i<=n;i++)
    {
        in>>v[i].x>>v[i].y;
    }
    sort(&v[1],&v[n+1],cmp);
    for(i=2;i<=n;i++)
    {
        dc=v[i].y + v[u].y + v[i].x - v[u].x;
        if(dc>dmax)
        {
            dmax=dc;
        }
        if(v[i].y>v[u].y+v[i].x-v[u].x)
        {
            u=i;
        }
    }
    out<<dmax;
    return 0;
}