Cod sursa(job #2535188)

Utilizator dorufDoru Floare doruf Data 31 ianuarie 2020 17:09:17
Problema Carnati Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.85 kb
#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();
}