Pagini recente » Cod sursa (job #648041) | Cod sursa (job #2380900) | Cod sursa (job #767209) | Cod sursa (job #135222) | Cod sursa (job #2273661)
#include <fstream>
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
const int MAXN = 100005;
#define st first
#define nd second
pair<int, int> oi[MAXN];
priority_queue<pair<int, int> > heap;
int main()
{
ifstream fin("lupu.in");
ofstream fout("lupu.out");
int n, x, l;
fin >> n >> x >> l;
for(int i = 1; i <= n; ++i)
fin >> oi[i].st >> oi[i].nd;
sort(oi + 1, oi + n + 1);
long long tot = 0;
int pos = 1, out = n + 1;
while(x >= 0){
pos = 1;
while(pos <= n && oi[pos].st <= x){
if(pos != out)
heap.push({oi[pos].nd, pos});
pos++;
}
tot += heap.top().st;
out = heap.top().nd;
while(!heap.empty())
heap.pop();
x -= l;
}
fout << tot;
return 0;
}