Pagini recente » Cod sursa (job #1566408) | Cod sursa (job #1940667) | Cod sursa (job #2837656) | Cod sursa (job #1395849) | Cod sursa (job #547966)
Cod sursa(job #547966)
#include<fstream>
#include<queue>
using namespace std;
const int MaxN = 100005;
const char infile[] = "lupu.in";
const char outfile[] = "lupu.out";
ifstream f(infile);
ofstream g(outfile);
struct oaie{
int dist,lana;
}a[MaxN];
long long sol;
int n,x,l,dist,i;
priority_queue<int> h;
inline bool cmp( const oaie &a , const oaie &b)
{
return a.dist < b.dist;
}
int main()
{
f >> n >> x >> l;
for( i = 1 ; i <= n ; i++ )
f >> a[i].dist >> a[i].lana;
sort(a+1,a+n+1,cmp);
for(dist = 0 , i = 1 ; dist <= x && i <= n ; dist += l )
{
for( ; i <= n && a[i].dist <= dist ; i++ )
h.push(a[i].lana);
if( h.size() )
{
sol += h.top();
h.pop();
}
}
g << sol << '\n';
return 0;
}