Cod sursa(job #422888)

Utilizator FlorianFlorian Marcu Florian Data 23 martie 2010 12:03:43
Problema Carnati Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
using namespace std;
#include<fstream>
#include<algorithm>
typedef long long ll;
const int MAX_N = 2007;
ll N, C, SOL;
struct client { ll t, p; };
struct cmp
{
	bool operator()(const client &a, const client &b)const
	{
		return a.t < b.t;
	}
};
client A[MAX_N];
inline ll max(ll a, ll b) { return (a>b)?a:b; }
int main()
{
	ifstream in("carnati.in"); ofstream out("carnati.out");
	in>>N>>C;
	ll i, j, cur, ant, P, V;
	for(i = 1; i <= N; ++i) in>>A[i].t>>A[i].p;
	sort(A+1,A+N+1,cmp());
	for(i = 1; i <= N; ++i)
	{
		P = A[i].p;
		if(A[1].p >= P) ant = P - C;
		else ant = 0;
		SOL = max(SOL, ant);
		for(j = 2; j <= N; ++j)
		{
			V = 0;
			if( A[j].p >= P) V = P;
			cur = max( ant + V - C * ( A[j].t - A[j-1].t ), V - C );
			SOL = max( SOL, cur );
			ant = cur;
		}
	}
	out<<SOL<<"\n";
	return 0;
}