Pagini recente » Cod sursa (job #2807867) | Cod sursa (job #1213203) | Cod sursa (job #1448215) | Cod sursa (job #560153) | Cod sursa (job #358382)
Cod sursa(job #358382)
#include<fstream>
using namespace std;
ifstream f1 ("heavymetal.in");
ofstream f2 ("heavymetal.out");
int n,a[100001],b[100001];
int best[100001];
int main()
{
int i,tmax=0;
f1>>n;
for (i=1; i<=n; i++) {f1>>a[i]>>b[i]; if (b[i]>tmax) tmax=b[i];
for (i=1; i<=tmax; i++)
{
best[i]=best[i-1];
for (j=1; j<=n; j++)
if (b[j]==i) best[i]=max(best[i], best[a[j]] + (b[j] - a[j]));
f2<<best[tmax];
return 0;
}