Cod sursa(job #2500299)

Utilizator ardutgamerAndrei Bancila ardutgamer Data 27 noiembrie 2019 18:13:17
Problema Lupul Urias si Rau Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <iostream>
#include <fstream>
#include <queue>
#include <algorithm>
#include <climits>
#include <vector>

using namespace std;

struct oita {
	long long pasi, lana;
	bool operator<(const oita& other) const
	{
		if (lana == other.lana)
			return pasi > other.pasi;
		return lana < other.lana;
	}
};

vector<oita>oi[100005];
priority_queue<oita>pq;

int main()
{
	ifstream cin("lupu.in");
	ofstream cout("lupu.out");
	long long n, x, l, dst;
	long long maxPasi = INT_MIN;
	oita temp;
	cin >> n >> x >> l;
	for (int i = 1; i <= n; i++)
	{
		cin >> dst >> temp.lana;
		temp.pasi = (x-dst)/l+1;
		if (x - dst >= 0) {
			maxPasi = max(maxPasi, temp.pasi);
			oi[temp.pasi].push_back(temp);
		}
	}
	long long sum = 0;
	for (int i = maxPasi ; i >= 1 ; i--)
	{
		for (oita oaie : oi[i])
			pq.push(oaie);
		if (pq.empty())
			continue;
		sum += pq.top().lana;
		pq.pop();
	}
	cout << sum << "\n";
	return 0;
}