Cod sursa(job #1794570)

Utilizator MickeyTurcu Gabriel Mickey Data 1 noiembrie 2016 15:04:07
Problema Lupul Urias si Rau Scor 16
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.98 kb
#include<fstream>
#include<string.h>
#include<ctype.h>
#include<iostream>
#include<algorithm>
#include<map>
#include<unordered_map>
#include<array>
#include<deque>
#include<math.h>
#include<functional>
#include<unordered_set>
#include<set>
#include<iomanip>
#include<bitset>
using namespace std;
int n,i,j,k,el,nr,ok,x,l,lana,dist,max1;
long long rez;
multimap<int, int>oi;
multimap<int, int>::iterator it;
int main()
{
	//ifstream f("file.in");
	//ofstream g("file.out");
	ifstream f("lupu.in");
	ofstream g("lupu.out");
	f >> n >> x >> l;
	for (i = 1; i <= n; i++)
	{
		f >> dist >> lana;
		if (dist <= x)
		{
			dist = (x - dist) / l + 1;
			oi.insert(make_pair(dist, lana));
		}
	}
	it = oi.begin(); 
	while (it != oi.end())
	{
		max1 = -1 * 1 << 30;
		dist = it->first;
		max1 = max(it->second, max1);
		it++;
		while (it != oi.end() && dist == it->first)
		{
			max1 = max(max1, it->second);
			it++;
		}
		rez += max1;
	}
	g << rez;
	return 0;
}