Cod sursa(job #1356051)

Utilizator alexandra_udristoiuUdristoiu Alexandra Maria alexandra_udristoiu Data 23 februarie 2015 09:48:14
Problema Carnati Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include<fstream>
using namespace std;
int n, i, j, maxim, x, pr, c;
int p[2001], t[2001], a[2001];
ifstream fin("carnati.in");
ofstream fout("carnati.out");
int main(){
	fin>> n >> c;
	for(i = 1; i <= n; i++){
		fin>> t[i] >> p[i];
	}
	for(j = 1; j <= n; j++){
		x = p[j];
		if(p[1] >= x){
			pr = x;
		}
		else{
			pr = 0;
		}
		a[1] = pr - c;
		for(i = 2; i <= n; i++){
			if(p[i] >= x){
				pr = x;
			}
			else{
				pr = 0;
			}
			a[i] = max(pr - c, a[i-1] + pr - (t[i] - t[i-1]) * c);
		}
		for(i = 1; i <= n; i++){
			maxim = max(maxim, a[i]);
		}
	}
	fout<< maxim <<"\n";
	return 0;
}