Cod sursa(job #2209057)

Utilizator toadehuPuscasu Razvan Stefan toadehu Data 1 iunie 2018 17:08:48
Problema Heavy metal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <bits/stdc++.h>

using namespace std;

struct heavymetal
{
    int x,y;
};
heavymetal v[100001];

int n,s=0,t=1,a[100001];

int cmp(heavymetal a,heavymetal b)
{
    if(a.y>b.y)
    {
        return false;
    }
    if(a.x>b.x && a.y==b.y)
    {
        return false;
    }
    return true;
}

int main()
{
    ifstream fin("heavymetal.in");
    ofstream fout("heavymetal.out");
    fin>>n;
    for(int i=1;i<=n;i++)
    {
        fin>>v[i].x>>v[i].y;
    }
    sort(v+1,v+n+1,cmp);
    for(int i=1;i<=v[n].y;i++)
    {
        a[i]=a[i-1];
        while(i==v[t].y)
        {
            a[i]=max(a[i],v[t].y-v[t].x+a[v[t].x]);
            t++;
        }
    }
    fout<<a[v[n].y];
}