Pagini recente » Cod sursa (job #1816325) | Cod sursa (job #1186913) | Cod sursa (job #3139024) | Cod sursa (job #43346) | Cod sursa (job #2413734)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("carnati.in");
ofstream g("carnati.out");
int n, c, last, i, w ;
int t[2005], p[2005], ind[2005];
long long s, maxim, care;
bool cmp(int a, int b)
{
return t[a] < t[b];
}
int main()
{
f >> n >> c;
for (i = 1; i <= n; i++)
f >> t[i] >> p[i], ind[i] = i;
sort(ind+1,ind+n+1,cmp);
t[0] = -1;
for (w = 1; w <= n; w++)
{
last = 0;
s = 0;
for (i = 1; i <= n; i++)
{
if (p[ind[i]] >= p[w])
{
if (s+p[w]-c*(t[ind[i]]-t[ind[last]]) >= p[w]-c)
s += p[w]-c*(t[ind[i]]-t[ind[last]]);
else
s = p[w]-c;
if (s > maxim)
maxim = s;
last = i;
}
}
}
g << maxim;
}