Pagini recente » Cod sursa (job #1800272) | Borderou de evaluare (job #1782783) | Cod sursa (job #921022) | Borderou de evaluare (job #2015512) | Cod sursa (job #2412353)
#include <fstream>
#include <set>
#include <algorithm>
using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");
set <int> S;
set <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);
for ( i=v[k].umom; i>=1; i-- ){
poz=k;
while ( poz >= 1 && 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;
}