Cod sursa(job #757085)

Utilizator Theorytheo .c Theory Data 10 iunie 2012 23:22:47
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include<fstream>
#include<algorithm>
#define nmax 50004
using namespace std;
ifstream fin("orase.in");
ofstream fout("orase.out");

int n,m;
struct oras{int d; int s;};

oras o[nmax];

inline bool cmp(oras a, oras b)
{
    return (a.d < b.d) || (a.d == b.d && a.s < b.s) ;
}

int maxii(int a, int b)
{
    if(a >b)
        return a;
    return b;
}
int solve()
{
    int maxi = -10000, maxt = -100000 ;
    int st = 1, dr = 2;
    for(st = 1, dr = 2; dr <= m; dr++)
    {
        maxi = maxii(maxi, o[dr].s + o[st].s + o[dr].d - o[st].d);
            if(o[dr].s > o[dr].d - o[st].d + o[st].s)
                st = dr;
    }
    return maxi;
}

void read()
{
    fin >>n >> m ;
    for(int i = 1; i <= m ;i++)
        fin >>o[i].d >> o[i].s;

    sort(o + 1, o + 1 + m, cmp);


}
int main()
{
    read();
    fout<<solve();
    fin.close();
    return 0;
}