Pagini recente » Borderou de evaluare (job #1750229) | Borderou de evaluare (job #2015725) | Borderou de evaluare (job #1249997) | Cod sursa (job #911305) | Cod sursa (job #2412359)
#include <fstream>
#include <set>
#include <algorithm>
using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");
multiset <int> S;
multiset <int>::iterator it;
struct potae{
int lana;
int umom;
} v[100009];
bool cmp (const potae &a, const potae &b){
return ( a.umom > b.umom );
}
int n,x,l,i,k,sol,poz,d,L;
int main()
{
f>>n>>x>>L;
for( i=1; i <= n; i++ ){
f>>d>>l;
if ( d <= x ) v[++k].lana=l, v[k].umom = 1 + (x-d)/L;
}
sort (v+1, v+k+1, cmp);
poz=1;
for ( i=v[1].umom; i>=1; i-- ){
while ( poz <= k && v[poz].umom==i)
S.insert ( v[poz].lana ), poz++;
if ( !S.empty() ){
it=S.end(); it--;
sol += *it;
S.erase(it);
}
}
g<<sol;
return 0;
}