Cod sursa(job #2130597)

Utilizator shantih1Alex S Hill shantih1 Data 13 februarie 2018 19:26:58
Problema Carnati Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("carnati.in");
ofstream fout("carnati.out");

long long n,i,j,nr,mx,prof,pret,s,c;
bool b[1000005];
struct om
{	int t,p;	} v[2005];
bool comp(om x,om y)
{	return x.t<y.t;	}

int main() {
	
	fin>>n>>c;
	for(i=1;i<=n;i++)
		fin>>v[i].t>>v[i].p;
	sort(v+1,v+n+1,comp);
	
	v[0].t=v[1].t-1;
	for(j=1;j<=n;j++)
	{
		if(b[v[j].p]==0)
		{
			b[v[j].p]=1;
			mx=0;
			s=0;
			for(i=1;i<=n;i++)
			{
				if(v[i].p>=v[j].p)	s+=v[j].p;
				s-=(v[i].t-v[i-1].t)*c;
				if(v[j].p-c>s&&v[i].p>=v[j].p)	s=v[j].p-c;
				if(s>mx)	mx=s;
			}
			if(mx>prof)	prof=mx;
		}
	}
	
	fout<<prof<<"\n";
}