Cod sursa(job #2204086)
| Utilizator | Data | 14 mai 2018 15:46:02 | |
|---|---|---|---|
| Problema | Heavy metal | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.65 kb |
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("heavymetal.in");
ofstream g("heavymetal.out");
struct hh{
int x,y;
};
hh v[100001];
int n,i,s=0,t=1,a[100001];
int cmp(hh a,hh b)
{
if(a.y>b.y)
return false;
if(a.x>b.x && a.y==b.y)
return false;
return true;
}
int main()
{
f>>n;
for(i=1;i<=n;i++)
f>>v[i].x>>v[i].y;
sort(v+1,v+n+1,cmp);
for(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++;
}
}
g<<a[v[n].y];
return 0;
}
