Cod sursa(job #1424626)

Utilizator tamionvTamio Vesa Nakajima tamionv Data 25 aprilie 2015 05:15:08
Problema Lupul Urias si Rau Scor 88
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

int main(){
	ifstream f("lupu.in");
	long long n, x, l;
	f >> n >> x >> l;
	vector<pair<int, int> > oi;
	oi.resize(n);
	int dist, ultima_tura = 0;
	for(auto& oaie : oi){
		f >> dist;
		f >> oaie.second;
		oaie.first = (x - dist)/l;
		if(ultima_tura < oaie.first){
			ultima_tura = oaie.first; } }
	sort(begin(oi), end(oi), [](const pair<int, int>& lhs, const pair<int, int>& rhs){
		return lhs.first > rhs.first; });
	int tura_curenta = ultima_tura;
	long long rez = 0;
	priority_queue<int> oi_posibile;

	for(auto it = begin(oi); it != end(oi) && tura_curenta >= 0; ){
		while(it != end(oi) && it->first == tura_curenta){
			oi_posibile.push(it->second);
			++it; }
		rez += oi_posibile.top();
		oi_posibile.pop();
		--tura_curenta; }

	ofstream g("lupu.out");
	g << rez;
	return 0; }