Cod sursa(job #1414033)

Utilizator theprdvtheprdv theprdv Data 2 aprilie 2015 11:59:17
Problema Lupul Urias si Rau Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <fstream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>

using namespace std;

fstream fin("lupu.in", ios::in);
fstream fout("lupu.out", ios::out);
#define MAXN 100005
int N, X, L, maxx;
unsigned long long int sol;
vector <long long int> sheeps[MAXN];

void read()
{
	fin >> N >> X >> L;
	for (int i = 1, w, z, gr; i <= N; i++){
		fin >> w >> z;
		if(w > 0) gr = (w - 1) / L + 1;
		if (w > X) continue;
		else gr = 0;
		if (gr > maxx) maxx = gr;
		sheeps[gr].push_back(z);
	}
	fin.close();
}

int main() 
{
	read();
	priority_queue <int, vector<int>> heap;
	for (int i = 0; i <= maxx; i++){
		while (!sheeps[i].empty()){
			heap.push(sheeps[i].back());
			sheeps[i].pop_back();
		}
		int add = 0;
		if (heap.size())  add = heap.top(), heap.pop();
		sol += add;
	}
	fout << sol << "\n";
	
	fout.close();
	return 0;
}