Pagini recente » Cod sursa (job #2662880) | Cod sursa (job #112486) | Cod sursa (job #31063) | Cod sursa (job #1823146) | Cod sursa (job #2928115)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("carnati.in");
ofstream fout("carnati.out");
const int LMAX = 2007;
struct client
{
int t, p;
};
bool cmp(client a, client b)
{
if (a.t != b.t)
return a.t < b.t;
return a.p < b.p;
}
int main()
{
int n, c;
fin >> n >> c;
vector<client> v(n);
for (int i = 0; i < n; i++)
fin >> v[i].t >> v[i].p;
sort(v.begin(), v.end(), cmp);
int ans = INT_MIN;
for(int i = 0; i < n; i++)
{
int sum = 0;
int prof = INT_MIN;
for(int j = 1; j < n; j++)
{
sum -= (v[j].t - v[j - 1].t) * c;
if(sum < 0)
sum = 0;
if (v[j].p >= v[i].p)
sum += v[i].p;
prof = max(prof, sum);
}
ans = max(prof, ans);
}
fout << ans;
return 0;
}