Cod sursa(job #2286674)

Utilizator eu3neuomManghiuc Teodor-Florin eu3neuom Data 20 noiembrie 2018 17:15:14
Problema Lupul Urias si Rau Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;

ifstream fin("lupu.in");
ofstream fout("lupu.out");
 
int main() {
    ios::sync_with_stdio(false);

	int n, x, l;
	fin >> n >> x >> l;

	vector < pair < ll, ll > > v(n);
	for (auto &x: v) fin >> x.first >> x.second;

	set < ll > Set;
	sort(v.begin(), v.end());
	for (int i = n - 1; i >= 0; --i) {
		if (v[i].first > x) {
			continue;
		} else {
			Set.insert(v[i].second);
			
			int mx = (x - v[i].first + 1) / l + ((x - v[i].first + 1) % l != 0);
			if (Set.size() > mx) {
				Set.erase(Set.begin());
			}
		}
	}

	ll ans = 0;
	for (auto x: Set) {
		ans += x;
	}

	fout << ans;
    return 0;
}