Pagini recente » Cod sursa (job #703331) | Cod sursa (job #2047993) | Winter Challenge, Clasele XI - XII | Cod sursa (job #1188092) | Cod sursa (job #2954760)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream cin ("carnati.in");
ofstream cout ("carnati.out");
const int N = 2000;
class upsy
{
public:
int timp, plata;
bool operator < (const upsy &a)const
{
return timp < a.timp;
}
} a[N + 1];
int n, cost, profit, ups = -1, preta;
int main()
{
cin >> n >> cost;
for (int i = 1; i <= n; ++i)
cin >> a[i].timp >> a[i].plata;
sort (a + 1, a + n + 1);
a[0].timp = a[1].timp - 1;
for (int i = 1; i <= n; ++i)
{
int pret = a[i].plata;
ups = -1;
for (int j = 1; j <= n; ++j)
{
int val = (a[j - 1].timp - a[j].timp) * cost;
int val1 = -cost;
if (a[j].plata >= pret)
val += pret, val1 += pret;
if (ups + val < val1)
ups = val1;
else
ups += val;
profit = max (profit, ups);
}
}
cout << profit <<'\n';
return 0;
}