Cod sursa(job #1369006)

Utilizator andrei_diaconuAndrei Diaconu andrei_diaconu Data 2 martie 2015 21:06:56
Problema Carnati Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <fstream>
#include <algorithm>
#define NMax 2001
using namespace std;
ifstream f("carnati.in");
ofstream g("carnati.out");
int n, c, d[NMax], i, j, bg, Max = -1;
struct oameni
{
	int timp;
	int pret;
}o[NMax];
int getmax(int a, int b)
{
	if (a > b)
		return a;
	return b;
}
bool cmp(const oameni &o1, const oameni &o2)
{
	return o1.timp < o2.timp;
}
int main()
{
	f >> n >> c;
	for (i = 1; i <= n; i++)
		f >> o[i].timp >> o[i].pret;
	o[0].timp = o[1].timp - 1;
	for (i = 1; i <= n; i++) {
		int pret = o[i].pret;
		for (j = 1; j <= n; j++) {
			if (o[j].pret >= pret)
				d[j] = getmax(d[j - 1] - (o[j].timp - o[j - 1].timp) * c + pret, pret - c);
			else
				d[j] = getmax(d[j - 1] - (o[j].timp - o[j - 1].timp) * c, - c);
			if (Max < d[j])
				Max = d[j];
		}
	}
	g << Max;
	return 0;
}