Cod sursa(job #3137703)

Utilizator Ilie_MityIlie Dumitru Ilie_Mity Data 14 iunie 2023 17:02:30
Problema Lupul Urias si Rau Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.86 kb
//Ilie Dumitru
#include<cstdio>
#include<queue>
const int NMAX=100005;

struct oaie
{
	int stepsLeft, puf;

	friend bool operator<(oaie a, oaie b)
	{
		return a.stepsLeft>b.stepsLeft;
	}
};

std::priority_queue<oaie> pq;
std::priority_queue<int, std::vector<int>, std::greater<int> > aux;

int main()
{
	FILE* f=fopen("lupu.in", "r"), *g=fopen("lupu.out", "w");
	//FILE* f=stdin, *g=stdout;
	int N, x, l, i;
	long long int ans=0;
	oaie o;

	fscanf(f, "%d%d%d", &N, &x, &l);
	for(i=0;i<N;++i)
	{
		fscanf(f, "%d%d", &o.stepsLeft, &o.puf);
		o.stepsLeft=(x-o.stepsLeft)/l;
		pq.push(o);
	}

	do
	{
		o=pq.top();
		pq.pop();

		aux.push(o.puf);
		if((int)aux.size()>o.stepsLeft+1)
			aux.pop();
	}while(!pq.empty());

	for(;!aux.empty();aux.pop())
		ans+=aux.top();
	fprintf(g, "%lld\n", ans);

	fclose(f);
	fclose(g);
	return 0;
}