Cod sursa(job #2593787)

Utilizator MerlinTheWizardMelvin Abibula MerlinTheWizard Data 4 aprilie 2020 16:33:52
Problema Orase Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.83 kb
#include<iostream>
#include<fstream>
#include<algorithm>
using namespace std;
ifstream f("orase.in");
ofstream g("orase.out");
struct orase
{
    int x,y;
};
bool fcmp (const orase nr1, const orase nr2)
{
    if(nr1.x==nr2.x)
        return(nr1.y<nr2.y);
    else
        return (nr1.x<nr2.x);
}
int main()
{
    int n,m;
    f>>m>>n;
    orase a[50001];
    for(int i=1;i<=n;i++)
    {
        f>>a[i].x;
        f>>a[i].y;
    }
    sort(a+1,a+n+1,fcmp);
    int i,j,xmax,ymax,x,y,best;
    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;
           }
    }

    g<<best<<"\n";
}