Cod sursa(job #1658643)

Utilizator tudoroprisTudor Opris tudoropris Data 21 martie 2016 18:19:40
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.06 kb
#include<iostream>
#include<fstream>
#include<algorithm>
#define nmax 50009

using namespace std;

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

struct coord{
    int x,y;
};

coord a[nmax];
int best, m, n;

inline bool Cmp(const coord nr1, const coord nr2)
{
    if (nr1.x == nr2.x) return (nr1.y < nr2.y);
    return (nr1.x < nr2.x);
}

void Citire()
{
    int i, j;
    fin >> m >> n;

    for (i=1; i<=n; i++)
        fin >> a[i].x >> a[i].y;
}

void Sortare()
{
    sort (a+1, a+n+1, Cmp);
}

void Rezolva()
{
    int i, j, xmax, ymax, x, y;
    best = -10;

    xmax = a[1].x; ymax = a[1].y;

    for (i=2; i<=n; i++)
    {

        x = a[i].x;   y = a[i].y;

        if (y + ymax + x - xmax > best)
            best = y + ymax + x - xmax;

        if (y > ymax + x - xmax)
           {
               ymax = y;
               xmax = x;
           }
    }

    fout << best << "\n";
}

int main ()
{
    Citire();
    Sortare();
    Rezolva();
    fin.close();
    fout.close();
    return 0;
}