Pagini recente » Cod sursa (job #781760) | Cod sursa (job #758994) | Cod sursa (job #195725) | Cod sursa (job #3127540) | Cod sursa (job #2051083)
#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);
for (w = 1; w <= n; w++) {
last = 1;
s = -c;
if (p[ind[i]]>=p[w])
s += p[w];
for (i = 2; 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;
}