Pagini recente » Cod sursa (job #602381) | Cod sursa (job #2319457) | Cod sursa (job #74711) | Cod sursa (job #439584) | Cod sursa (job #1051150)
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#define mp make_pair
using namespace std;
vector<pair<int,int> > V;
multiset<int> H;
multiset<int>::iterator it2;
vector<pair<int,int> >::iterator it,lim;
int N, L, K, i, x, cost;
long long Total;
bool cmp(pair<int,int> A, pair<int,int> B)
{
if (A.second >B.second) return 1;
return 0;
}
int main()
{
freopen("lupu.in", "r", stdin);
freopen("lupu.out", "w", stdout);
scanf("%d%d%d", &N, &L, &K);
for (i=1; i<=N; i++)
{
scanf("%d%d", &x, &cost);
V.push_back( mp( cost, (L-x)/K+1 ) );
}
sort(V.begin(), V.end(), cmp);
x=(*V.begin()).second;
it=V.begin();
lim=V.end();
while (x>0)
{
while ((*it).second==x && it!=lim)
{
H.insert( (*it).first );
it++;
}
it2=H.end();
it2--;
Total+=*it2;
H.erase( it2 );
x--;
}
printf("%lld\n", Total);
return 0;
}