Cod sursa(job #2500297)

Utilizator ardutgamerAndrei Bancila ardutgamer Data 27 noiembrie 2019 18:10:29
Problema Lupul Urias si Rau Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.91 kb
#include <iostream>
#include <fstream>
#include <queue>
#include <algorithm>
#include <climits>
#include <vector>
#define int long long
using namespace std;

struct oita {
	int 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;

__int32 main()
{
	ifstream cin("lupu.in");
	ofstream cout("lupu.out");
	int n, x, l, dst;
	int 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;
		maxPasi = max(maxPasi, temp.pasi);
		oi[temp.pasi].push_back(temp);
	}
	int 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;
}