Cod sursa(job #1722868)

Utilizator andreiSevastreAndrei Sevastre andreiSevastre Data 29 iunie 2016 10:28:50
Problema Heavy metal Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <iostream>
#include <stdio.h>
#define MAXVAL 100001
using namespace std;

int v[MAXVAL],timp;

int maxim (int x,int y)
{
	return x>y? x:y;
}
int main ()
{
	int n,a,b;
	
	freopen ("heavymetal.in", "r", stdin);
	freopen ("heavymetal.out", "w", stdout);
	
	scanf("%d", &n);
	
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d", &a,&b);
		
		for(int j=20; j>=1; j--)
		{
			if (v[j]!=0)
			{
				v[j+a]=maxim(v[j+a], v[j]+(b-a));
			}
		}
		if(v[a])
		{
			timp+=v[a];
		}
		else 
		{
			v[a]=b-a;
		}
	}
	
	printf("%d",timp);
	
return 0;

}