Cod sursa(job #810314)

Utilizator paunmatei7FMI Paun Matei paunmatei7 Data 10 noiembrie 2012 09:36:54
Problema Carnati Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include<stdio.h>
#include<algorithm>
#define x first
#define y second
#define l long
using namespace std;

pair<l,l>a[2007];

l b[1607];

int main()
{
	
	l n,s,max2=-300000007;
	
	freopen("carnati.in","r",stdin);
	freopen("carnati.out","w",stdout);
	
	scanf("%d%d",&n,&s);
	
	for(l i=1;i<=n;++i)
		scanf("%ld%ld",&a[i].x,&a[i].y);
	
	sort(a+1,a+n+1);//sortare
	
	for(l j=1;j<=n;++j)
	{
		
		//b=sume
		
		int u=1;
		
		for(l i=0;i<=a[n].x;++i)
		{
			
			b[i]=b[i-1]-s;
			
			while(a[u].x==i)
				if(a[u++].y>=a[j].y)
					b[i]+=a[j].y;
			
		}
		
		l min2=0;
		
		//solutie
		
		for(l i=0;i<=a[n].x;++i)
			min2=min(min2,b[i]),max2=max(max2,b[i]-min2);
		
	}
	
	printf("%ld\n",max2);//afisez maxim
	
	return 0;

}