Pagini recente » Cod sursa (job #2718142) | Cod sursa (job #2729557) | Cod sursa (job #1879694) | Cod sursa (job #2797295) | Cod sursa (job #1322107)
//
// main.cpp
// lupu
//
// Created by Alex Petrache on 19/01/15.
// Copyright (c) 2015 Alex Petrache. All rights reserved.
//
#include<fstream>
#include<algorithm>
#include<queue>
using namespace std;
int n,x,l,i,d;
priority_queue<int>q;
struct oaie
{
int t,l;
}v[100009];
bool cmp(oaie a,oaie b)
{
return (a.t>b.t);
}
int main()
{
ifstream f("lupu.in");
ofstream g("lupu.out");
f>>n>>x>>l;
for (i=1;i<=n;++i)
{
f>>d>>v[i].l;
if (d<=x)
v[i].t=(x-d)/l+1;
}
sort(v+1,v+n+1,cmp);
i=1;
long long sum=0,k;
for (k=v[i].t;k>0;k--)
{
while (i<=n && v[i].t==k)
{
q.push(v[i].l);
i++;
}
if (!q.empty()) {sum+=q.top();q.pop();}
}
g<<sum<<'\n';
return 0;
}