Cod sursa(job #1155448)

Utilizator cristinamateiCristina Matei cristinamatei Data 26 martie 2014 22:04:03
Problema Orase Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <fstream>

using namespace std;

struct pereche
{
    int d,l;
};
pereche a[50000];

int main()
{
    ifstream in("orase.in");
    ofstream out("orase.out");
    int n, m, i, distmax = 0, j, s;
    in >> m >> n;
    for ( i = 1; i <= n; i++ )
    {
        in >> a[i].d >> a[i].l;
    }
    for ( i = 1; i < n; i++ )
    {
        for ( j = i+1; j <= n; j++ )
        {
            s = a[i].l + a[j].l;
            if ( a[i].d > a[j].d )
                s = s+ a[i].d - a[j].d;
            else
                s = s + a[j].d - a[i].d;
            if ( s > distmax )
                distmax = s;
        }
    }
    out << distmax;
    return 0;
}