Pagini recente » Cod sursa (job #2718188) | Cod sursa (job #2754809) | Cod sursa (job #1045240) | Cod sursa (job #2449647) | Cod sursa (job #2461349)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("lupu.in");
ofstream fout("lupu.out");
int n, x, l, ans, tmax;
vector < pair <int, int > > v;
vector <int> check;
vector <int> :: iterator it;
int main()
{
fin >> n >> x >> l;
for(int i = 1; i <= n; i++)
{
int a, b;
fin >> a >> b;
int times;
if(x < a) times = 0;
else
times = (x-a)/l+1;
if(times)
v.push_back(make_pair(b, times));
tmax = max(tmax, times);
}
while(tmax >= 1)
{
check.push_back(-tmax);
tmax--;
}
sort(v.begin(), v.end());
for(int i = v.size()-1; i >= 0; i--)
{
int cost, t;
cost = v[i].first;
t = v[i].second;
it = lower_bound(check.begin(), check.end(), -t);
int x= *it;
if(it != check.end())
{
ans += cost;
check.erase(it);
}
}
fout << ans;
return 0;
}