Pagini recente » Cod sursa (job #385268) | Cod sursa (job #3150063) | Cod sursa (job #2558673) | Cod sursa (job #2066090) | Cod sursa (job #196587)
Cod sursa(job #196587)
#include<stdio.h>
#include<algorithm>
using namespace std;
#define nmax 2024
typedef struct{
int cost,timp;
}q;
q v[nmax];
inline int cmp(q A,q B)
{
return A.timp<B.timp;
}
inline int max(const int a,const int b)
{
if( a>b )
return a;
return b;
}
int main(){
freopen("carnati.in","r",stdin);
freopen("carnati.out","w",stdout);
int N,U;
scanf("%d%d",&N,&U);
int i,j;
int a1,a2;
for(i=1,j=0; i<=N; ++i)
{
scanf("%d%d",&a1,&a2);
if( a2>U )
{
v[++j].timp=a1;
v[j].cost=a2;
}
}
N=j;
sort(v+1,v+1+N,cmp);
int sum,solfin=0,timp,tsol;
int sol,aux;
int tmin,tmax;
for(i=1; i<=N; ++i)
{
tsol=v[i].cost;
sol=tsol-U;
tmin=tmax=v[i].timp;
for(j=1; j<=N; ++j)
if( j!=i && v[j].cost>=tsol )
{
aux=0;
if( v[j].timp < tmin )
aux=tmin-v[j].timp;
if( v[j].timp > tmax )
aux=v[j].timp-tmax;
a1=sol+tsol-(aux*U);
if( a1> sol )
{
sol=a1;
if( v[j].timp < tmin )
tmin=v[j].timp;
else
if( v[j].timp > tmax )
tmax=v[j].timp;
}
}
solfin=max(solfin,sol);
}
printf("%d\n",solfin);
return 0;
}