Pagini recente » Cod sursa (job #1707205) | Cod sursa (job #2389220) | Cod sursa (job #3205301) | Cod sursa (job #3257280) | Cod sursa (job #2535188)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("carnati.in");
ofstream fout("carnati.out");
struct Customer {
int time, limit;
bool operator < (const Customer& C) const
{ return limit > C.limit; }
};
const int T = 1505, N = 2005;
const int Inf = 0x3f3f3f3f;
Customer a[N];
int t[T], n, salary, profit = -Inf;
int main()
{
ios_base::sync_with_stdio(false);
fin.tie(0);
fout.tie(0);
fin >> n >> salary;
for (int i = 1; i <= n; ++i)
fin >> a[i].time >> a[i].limit;
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; ++i)
{
++t[a[i].time];
int current = 0;
for (int j = 0; j < T; ++j)
{
if (current > 0)
current += t[j] * a[i].limit - salary;
else
current = t[j] * a[i].limit - salary;
profit = max(profit, current);
}
}
fout << profit;
fin.close();
fout.close();
}