Pagini recente » Cod sursa (job #2937201) | Cod sursa (job #17121) | Cod sursa (job #2135774) | Cod sursa (job #1679453) | Cod sursa (job #2813470)
#include <iostream>
#include <fstream>
#include <queue>
#include <algorithm>
using namespace std;
ifstream in("lupu.in");
ofstream out("lupu.out");
const int MAXN = 100000;
struct Sheep{
int poz, val;
};
Sheep sheep[MAXN];
priority_queue<int> heap;
void inser( int val ){
heap.push(val);
}
int myTop(){
int top;
top = 0;
if( !heap.empty() ){
top = heap.top();
heap.pop();
}
return top;
}
bool cmp( const Sheep &a, const Sheep &b ){
return a.poz < b.poz;
}
int main()
{
long long totalLana = 0;
int n, x, l, i, d;
in>>n>>x>>l;
for( i = 0; i < n; i++ ){
in>>sheep[i].poz>>sheep[i].val;
}
sort(sheep, sheep + n, cmp);
d = x % l;
totalLana = 0;
i = 0;
while(d <= x ){
while( i <= n && sheep[i].poz <= d ){
inser(sheep[i++].val);
}
totalLana+=myTop();
d+=l;
}
out<<totalLana;
return 0;
}