Cod sursa(job #2561881)

Utilizator VladMxPMihaila Vlad VladMxP Data 29 februarie 2020 10:56:19
Problema Heavy metal Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("heavymetal.in");
ofstream fout("heavymetal.out");
int n,nr,yf,a[100000000];
struct spect
{
    int x,y;
};
spect v[100001];
bool comp(spect a,spect b)
{
    return a.y<b.y||(a.y==b.y&&a.x>b.x);
}
int main()
{
    int i,j;
    fin>>n;
    for(i=1;i<=n;i++)fin>>v[i].x>>v[i].y;
    sort(v+1,v+n+1,comp);
    i=1;
    for(j=1;j<=v[n].y;j++)
    {
        a[j]=a[j-1];
        while(v[i].y==j)
        {
            a[j]=max(a[j],a[v[i].x]+v[i].y-v[i].x);
            i++;
        }
    }
    fout<<a[v[n].y];
}