Pagini recente » Cod sursa (job #1428656) | Cod sursa (job #355241) | Cod sursa (job #1542620) | Cod sursa (job #200493) | Cod sursa (job #1947614)
#include <stdio.h>
#include <algorithm>
using namespace std;
struct customer{int t, p;};
customer v[2010];
int t[2010], p[2010], a[2010];
bool cmp (customer a, customer b) {
return a.t < b.t;
}
int main()
{
FILE *fin, *fout;
int n, c, i, j, mx;
fin = fopen ("carnati.in", "r");
fout = fopen ("carnati.out", "w");
fscanf (fin, "%d%d", &n, &c);
for (i = 1; i <= n; i++)
fscanf (fin, "%d%d", &v[i].t, &v[i].p);
sort (v + 1, v + n + 1, cmp);
mx = 0;
for ( i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
if ( v[i].p <= v[j].p )
a[j] = max (a[j - 1] - (v[j].t - v[j - 1].t) * c + v[i].p, v[i].p - c);
else
a[j] = max (-c, a[j - 1] - (v[j].t - v[j - 1].t) * c);
if (mx < a[j])
mx = a[j];
}
}
fprintf (fout, "%d\n", mx);
fclose (fin);
fclose (fout);
return 0;
}