Pagini recente » Cod sursa (job #2799853) | Cod sursa (job #804852) | Cod sursa (job #2407757) | Cod sursa (job #2368582) | Cod sursa (job #422893)
Cod sursa(job #422893)
using namespace std;
#include<cstdio>
#include<algorithm>
#define DIM 8192
char vec[DIM];
int pz;
typedef int ll;
const int MAX_N = 2048;
ll N, C, SOL;
struct client { ll t, p; };
struct cmp
{
bool operator()(const client &a, const client &b)const
{
return a.t < b.t;
}
};
client A[MAX_N];
inline ll max(ll a, ll b) { return (a>b)?a:b; }
void cit(int &x)
{
x=0;
while(vec[pz]<'0' || vec[pz]>'9')
if(++pz==DIM) fread(vec,1,DIM,stdin),pz=0;
while(vec[pz]>='0' && vec[pz]<='9')
{
x=x*10+vec[pz]-'0';
if(++pz==DIM)fread(vec, 1, DIM, stdin),pz=0;
}
}
int main()
{
freopen("carnati.in","r",stdin); freopen("carnati.out","w",stdout);
cit(N), cit(C);
ll i, j, cur, ant, P, V;
for(i = 1; i <= N; ++i) cit(A[i].t),cit(A[i].p);
sort(A+1,A+N+1,cmp());
for(i = 1; i <= N; ++i)
{
P = A[i].p;
if(A[1].p >= P) ant = P - C;
else ant = 0;
SOL = max(SOL, ant);
for(j = 2; j <= N; ++j)
{
V = 0;
if( A[j].p >= P) V = P;
cur = max( ant + V - C * ( A[j].t - A[j-1].t ), V - C );
SOL = max( SOL, cur );
ant = cur;
}
}
printf("%d\n",SOL);
return 0;
}