Cod sursa(job #1355955)

Utilizator CostanMiriamCostan Miriam CostanMiriam Data 23 februarie 2015 02:27:38
Problema Carnati Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <fstream>
#include <algorithm>

using namespace std;

ifstream fin("carnati.in");
ofstream fout("carnati.out");

struct cumparator{
	int t;
	int p;
}v[2010];

int n, c, maxim;

int d[2010];

bool cmp(const cumparator &a, const cumparator &b){
	return (a.t < b.t);
}

int main() {

	fin >> n >> c;

	for (int i = 1; i <= n; i++)
		fin >> v[i].t >> v[i].p;

	sort(v + 1, v + n + 1, cmp);

	v[0].t = v[1].t - 1;

	for (int i = 1; i <= n; i++) {

		for (int j = 1; j <= n; j++) {

			d[j] = 0;

			if (v[j].p >= v[i].p)
				d[j] = v[i].p;
			d[j] = max(d[j] + d[j - 1] - (v[j].t - v[j - 1].t) * c, d[j] - c);

			maxim = max(maxim, d[j]);
		}
	
	}

	fout << maxim << "\n";

	return 0;
}