Pagini recente » Monitorul de evaluare | Monitorul de evaluare | Monitorul de evaluare | Monitorul de evaluare | Cod sursa (job #3332309)
#include <fstream>
#include <queue>
#include <algorithm>
using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");
priority_queue<int, vector<int>, greater<int>> pq;
pair<int, int> a[100005];
int main()
{
f.tie(NULL);
ios_base::sync_with_stdio(0);
int n, x, l;
f >> n >> x >> l;
for(int i = 1; i <= n; i++)
{
int d, c;
f >> d >> c;
if(d > x) {
n--, i--;
continue;
}
a[i] = {1 + (x - d) / l, c};
}
sort(a + 1, a + n + 1);
long long ans = 0;
for(int i = 1; i <= n; i++)
{
ans += a[i].second;
pq.push(a[i].second);
if(pq.size() > a[i].first) {
ans -= pq.top();
pq.pop();
}
}
g << ans;
return 0;
}