Cod sursa(job #15006)

Utilizator bogdan2412Bogdan-Cristian Tataroiu bogdan2412 Data 10 februarie 2007 15:36:27
Problema Euro Scor 25
Compilator c Status done
Runda Arhiva de probleme Marime 0.49 kb
#include <stdio.h>

#define MAXN 34569

int N, T;
int x[MAXN];
long long best[MAXN];

int main()
{
	freopen("euro.in", "rt", stdin);
	freopen("euro.out", "wt", stdout);
	scanf("%d %d", &N, &T);
	best[0] = 0;
	int i;
	for (i = 1; i <= N; i++)
	{
		scanf("%d", x + i);
		best[i] = -(1LL << 60);

		int j; long long S = 0;
		for (j = i; j && i - j <= 1000; j--)
		{
			S += i * x[j];

			if (best[j - 1] + S - T> best[i])
				best[i] = best[j - 1] + S - T;
		}
	}
	printf("%lld\n", best[N]);
	return 0;
}