Pagini recente » Monitorul de evaluare | Statistici Ienciu Antoniu (tonyyy_14) | Cod sursa (job #248895) | Statistici MarincasValentin (MarincasValentin) | Cod sursa (job #1756051)
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
#define NMAX 2005
struct client{
int timp;
int pret;
} v[ NMAX ];
bool cmp( client a, client b ){
return a.timp < b.timp;
}
int main()
{
freopen("carnati.in","r",stdin);
freopen("carnati.out","w",stdout);
int n, m, i, j, s, t, d, c, pret, program, maxi;
maxi = -99999999;
scanf("%d%d",&n,&c);
for( i = 1; i <= n; ++i ) scanf("%d%d",&v[ i ].timp,&v[ i ].pret);
sort( v + 1, v + 1 + n, cmp );
for( i = 1; i <= n; ++i ){
pret = v[ i ].pret;
s = program = 0;
for( j = 1; j <= n; ++j ){
if( v[ j ].pret >= pret ){
if( program == 0 ) program = v[ j ].timp - 1;
s += pret - ( v[ j ].timp - program ) * c;
program = v[ j ].timp;
if( s < pret - c ) s = pret - c;
if( s > maxi ) maxi = s;
}
}
}
printf("%d",maxi);
return 0;
}