Pagini recente » Cod sursa (job #1407603) | Cod sursa (job #2161578) | Cod sursa (job #2595735) | Cod sursa (job #3279174) | Cod sursa (job #344687)
Cod sursa(job #344687)
#include<fstream>
#define dmax 100002
using namespace std;
ifstream in("heavymetal.in");
ofstream out("heavymetal.out");
long n,temp[dmax];
struct formatii
{ long x;
long y;
} m[dmax];
typedef int compfn(const void *,const void *);
long sf(struct formatii *a,struct formatii *b)
{ return (a->x - b->x);
}
int main()
{ int i,j;
in>>n;
for(i=0;i<n;i++)
in>>m[i].x>>m[i].y;
in.close();
qsort((void*)&m,n,sizeof(struct formatii),(compfn*)sf);
for(i=0;i<n;i++)
{ if(i==0)
temp[i]=m[i].y-m[i].x;
else
{ temp[i]=m[i].y-m[i].x;
for(j=0;j<i;j++)
if(m[i].x>=m[j].y)
temp[i]=max(temp[i],temp[j]+m[i].y-m[i].x);
}
}
out<<temp[n-1];
out.close();
return 0;
}