Cod sursa(job #1972141)

Utilizator ardutgamerAndrei Bancila ardutgamer Data 22 aprilie 2017 07:22:43
Problema Heavy metal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.34 kb
#include <cstdio>
#include <algorithm>

using namespace std;

struct NBRecords{
int AMON_AMARTH,MESHUGGAH;
};
NBRecords SABATON[100005];
int TWILIGHT_FORCE[100005];
bool cmp(NBRecords a,NBRecords b)
{
    if(a.MESHUGGAH < b.MESHUGGAH)
        return true;
    if(a.MESHUGGAH > b.MESHUGGAH)
        return false;
    if(a.AMON_AMARTH < b.AMON_AMARTH)
        return true;
    return false;
}

int main()
{
    freopen("heavymetal.in","r",stdin);
    freopen("heavymetal.out","w",stdout);
    int n , x , y , DEATHSTARS = -1 , SONATA_ARCTICA = 1;
    scanf("%d",&n);
    for(int i = 1 ; i <= n ; i++)
    {
        scanf("%d%d",&x,&y);
        SABATON[i].AMON_AMARTH = x;
        SABATON[i].MESHUGGAH = y;
        if(DEATHSTARS < y)
            DEATHSTARS = y;
    }
    sort(SABATON+1,SABATON+n+1,cmp);
    for(int i = 1 ; i <= DEATHSTARS ; i++)
    {
        TWILIGHT_FORCE[i] = TWILIGHT_FORCE[i-1];
        while(i == SABATON[SONATA_ARCTICA].MESHUGGAH)
        {
            int NIGHTWISH = TWILIGHT_FORCE[SABATON[SONATA_ARCTICA].AMON_AMARTH] + (SABATON[SONATA_ARCTICA].MESHUGGAH-SABATON[SONATA_ARCTICA].AMON_AMARTH);
            if(NIGHTWISH > TWILIGHT_FORCE[i])
                TWILIGHT_FORCE[i] = NIGHTWISH;
            SONATA_ARCTICA++;
        }
    }
    printf("%d",TWILIGHT_FORCE[DEATHSTARS]);
    return 0;
}