Pagini recente » Cod sursa (job #3361551) | Cod sursa (job #3361549) | Cod sursa (job #3357890) | Cod sursa (job #3361969) | Cod sursa (job #3361461)
#include <fstream>
using namespace std;
ifstream fin("carnati.in");
ofstream fout("carnati.out");
int timp[2001];
long long pretClient[2001];
long long castig[1501];
int main()
{
int n;
long long c;
fin >> n >> c;
for (int i = 1; i <= n; i++)
fin >> timp[i] >> pretClient[i];
long long profitMaxim = 0;
for (int i = 1; i <= n; i++)
{
long long pret = pretClient[i];
for (int t = 0; t <= 1500; t++)
castig[t] = -c;
for (int j = 1; j <= n; j++)
{
if (pretClient[j] >= pret)
castig[timp[j]] = castig[timp[j]] + pret;
}
long long profitCurent = 0;
for (int t = 0; t <= 1500; t++)
{
profitCurent = profitCurent + castig[t];
if (profitCurent > profitMaxim)
profitMaxim = profitCurent;
if (profitCurent < 0)
profitCurent = 0;
}
}
fout << profitMaxim;
return 0;
}