Pagini recente » Cod sursa (job #1443594) | Cod sursa (job #1577141) | Cod sursa (job #157110) | Cod sursa (job #1908561) | Cod sursa (job #2650153)
#include <bits/stdc++.h>
using namespace std;
ifstream in("carnati.in");
ofstream out("carnati.out");
vector<int> times[1505];
int c;
int test(int price)
{
int max_here = 0, max_max = 0;
for(int i = 0; i < 1505; i++)
{
max_here -= c;
for(auto customer : times[i])
{
if(customer >= price) {
max_here += price;
}
}
max_max = max(max_max, max_here);
max_here = max(max_here, 0);
}
return max_max;
}
int main()
{
int n; in >> n >> c;
for(int i = 0; i < n; ++i)
{
int t, cc; in >> t >> cc;
times[t].push_back(cc);
}
int maxim = -1;
for(int i = 0; i < 1505; i++)
{
for(auto prc : times[i]) {
maxim = max(maxim, test(prc));
int num = test(prc);
//cout << prc << " " << num << endl;
}
}
out << maxim;
return 0;
}