Cod sursa(job #1958196)

Utilizator raulmuresanRaul Muresan raulmuresan Data 8 aprilie 2017 08:45:21
Problema Orase Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include<fstream>
#include<vector>
#include<string>
#include<algorithm>
#define modulo 666013

using namespace std;

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


const int NMAX = 50005;
int i, n, k, j,m,st,dr,sol,x,y,pozition,current;
struct orase
{
    int lungime, distanta;
};
orase a[NMAX];

bool cmp(orase a, orase b)
{
    return a.distanta < b.distanta;
}

int main()
{
    fin >> m >> n;
    for(i = 1; i <= n; i++)
    {
        fin >> a[i].distanta >> a[i].lungime;
    }
    sort(a + 1, a + n + 1, cmp);
    sol = 0;
    current = a[1].lungime;
    //pozition = a[1]
    for(i = 2; i <= n; i++)
    {
        current += (a[i].distanta - a[i - 1].distanta);
        sol = max(sol, current + a[i].lungime);
        current = max(current, a[i].lungime);
    }
    fout << sol << "\n";


    for(i = 1; i <= n; i++)
    {
        //fout << a[i].distanta << " " << a[i].lungime<<"\n";
    }

}