Pagini recente » Cod sursa (job #2873851) | Cod sursa (job #614070) | Cod sursa (job #2834402) | Cod sursa (job #2558339) | Cod sursa (job #2561881)
#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];
}