Pagini recente » Cod sursa (job #936444) | Cod sursa (job #1689599) | Cod sursa (job #934712) | Cod sursa (job #2109625) | Cod sursa (job #1536660)
#include <fstream>
#include <algorithm>
#define formula(x) rez-(a[j].t-a[j-1].t-(x))*c
using namespace std;
ifstream f("carnati.in");
ofstream g("carnati.out");
int n, c, i, j, max1;
struct J{
int t, p;
}a[2001];
int rez, r1, max0;
bool cmp(J a, J b)
{
return (a.t < b.t);
}
int main()
{
f >> n >> c;
for (i = 1; i <= n; i++)
f >> a[i].t >> a[i].p;
sort(a+1, a+n+1, cmp);
a[0].t = -1;
for (i = 1; i <= n; i++)
{
max0 = a[i].p, rez = 0;
for (j = 1; j <= n; j++)
{
r1 = 0;
if (a[j].p >= max0)
r1 = max0;
if (rez - (a[j].t-a[j-1].t-1)*c > 0)
rez += r1-(a[j].t-a[j-1].t)*c;
else
rez = r1-c;
if (max1 < rez)
max1 = rez;
}
}
g << max1;
return 0;
}