Cod sursa(job #1710572)

Utilizator pibogaBogdan piboga Data 29 mai 2016 12:16:36
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <fstream>
#include <cmath>

using namespace std;

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

struct sct
{
    int d,h;

}v[3];

int l,n,i,d,h,s,s1,s2,m;

int main()
{
    fin >> l >> n;

    fin >> v[0].d >> v[0].h;
    fin >> v[1].d >> v[1].h;

    s=v[0].h+v[1].h + abs(v[1].d - v[0].d);

    for (i=3;i<=n;i++)
    {
        fin >> d >> h;
        s1=v[0].h+ h + abs(v[0].d - d);
        s2=v[1].h+ h + abs(v[1].d - d);
        if (s1>s)
        {
            {
            v[1].d=d;
            v[1].h=h;
            s=s1;
            }
        }
        if (s2>s)
        {

            {
            v[0].d=d;
            v[0].h=h;
            s=s2;
            }
        }

    }
    fout << s;


    return 0;
}