Pagini recente » Cod sursa (job #1745431) | Cod sursa (job #2974752) | Cod sursa (job #2778066) | Cod sursa (job #1325912) | Cod sursa (job #502274)
Cod sursa(job #502274)
#include<fstream>
#include<queue>
#include<algorithm>
using namespace std;
struct casa{int d,c;} a[1005];
long long sol;
int n,x,l,dist,i;
priority_queue <int> h;
inline bool cmp (const casa &a,const casa &b)
{if(a.d<b.d)
return 1;
return 0;}
int main ()
{ifstream q("lupu.in");
ofstream w("lupu.out");
q>>n>>x>>l;
for(i=1;i<=n;i++)
q>>a[i].d>>a[i].c;
sort(a+1,a+n+1,cmp);
for(dist=0,i=1;dist<=x&&i<=n;dist+=l)
{for(;i<=n&&a[i].d<=dist;i++)
h.push(a[i].c);
if(h.size())
{sol+=h.top();
h.pop();}}
w<<sol<<"\n";
return 0;}