Pagini recente » Cod sursa (job #1717851) | Cod sursa (job #2443419) | Cod sursa (job #1273887) | Cod sursa (job #2076135) | Cod sursa (job #3224289)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("heavymetal.in");
ofstream fout("heavymetal.out");
struct timpu
{
int s,d;
}a[100005];
bool fcmp(timpu x, timpu y)
{
if(x.d>y.d) return 0;
return 1;
}
int n,v[100005],mx;
int main()
{
fin>>n;
for(int i=1;i<=n;i++)
fin>>a[i].s>>a[i].d;
sort(a+1,a+n+1,fcmp);
for(int i=1;i<=n;i++)
{
int x=a[i].s;
while(v[x]==0 && x>0)
x--;
int y=a[i].d;
while(v[y]==0 && y>0)
y--;
v[a[i].d]=max(v[x]+(a[i].d-a[i].s),v[y]);
if(mx<v[a[i].d]) mx=v[a[i].d];
}
fout<<mx;
return 0;
}