Pagini recente » Cod sursa (job #1412357) | Cod sursa (job #2784720) | Cod sursa (job #1933227) | Cod sursa (job #747476) | Cod sursa (job #3270233)
#include <bits/stdc++.h>
using namespace std;
ifstream f ("lupu.in");
ofstream g ("lupu.out");
const int NMAX = 1e5;
//sar din l in el luand cea mai buna optiune mereu cu un pq;
priority_queue<int> pq;
pair<int, int> v[NMAX+1];
int main()
{
int n, x, l;
f >> n >> x >> l;
for(int i=1; i<=n; i++)
f >> v[i].first >> v[i].second;
sort(v + 1, v + 1 + n);
int dmin = -1;
long long ans = 0;
int cnt = 1;
for(int i=0; i<=x/l; i++){
int dmax = i * l;
while(cnt <= n and v[cnt].first <= dmax)
pq.push(v[cnt].second), cnt ++;
if(!pq.empty()){
ans += pq.top();
pq.pop();
}
}
g << ans;
return 0;
}