Cod sursa(job #1220045)

Utilizator andreas.chelsauAndreas Chelsau andreas.chelsau Data 16 august 2014 13:44:01
Problema Carnati Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;

#define MAX(a,b) ((a) > (b) ? (a) : (b))

int n,c,a[2005],t[2005],rez[2005];

void solve(){
	for(int i = 0; i < n; i++)
		rez[i] = -c;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(a[i] <= a[j])
				rez[i] = MAX(rez[i],rez[i] + c + a[i] - (abs(t[j] - t[i]) + 1) * c);			
		}
	}
	int max = -(1 << 30);
	for(int i = 0; i < n; i++)
		max = rez[i] > max ? rez[i] : max;
	printf("%d\n",max);

}
int main(){
	freopen("carnati.in","r",stdin);
	freopen("carnati.out","w",stdout);

	scanf("%d%d",&n,&c);
	for(int i = 0; i < n; i++){
		scanf("%d%d",&t[i],&a[i]);
	}
	solve();

	return 0;
}