Cod sursa(job #499956)

Utilizator SpiderManSimoiu Robert SpiderMan Data 11 noiembrie 2010 09:28:18
Problema Lupul Urias si Rau Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.37 kb
# include <algorithm>
# include <cstdio>
# include <queue>
using namespace std ;

# define T first
# define D second.first
# define A second.second
# define verf ++poz == hg ? fread ( ch, 1, hg, stdin ), poz = 0 : 0

const char *FIN = "lupu.in", *FOU = "lupu.out" ;
const int MAX = 100005, hg = 1 << 13 ;

pair < int, pair < int, int > > V[MAX] ;
priority_queue < int > H ;
int N, X, L, maxi, poz ;
char ch[ hg ] ;

inline void cit ( int &x ) {
    if ( ch[0] == '\0' ) fread ( ch, 1, hg, stdin ) ;
    else for ( ; ch[poz] < '0' || ch[poz] > '9' ; verf ) ;
    for ( x = 0 ; ch[poz] >= '0' && ch[poz] <= '9' ; x = x * 10 + ch[poz] - '0', verf ) ;
}

void read_data ( void ) {
    freopen ( FIN, "r", stdin ) ;
    cit ( N ) , cit ( X ) , cit ( L ) ;

    for ( int i = 1; i <= N; ++i ) {
        cit ( V[i].D ) , cit ( V[i].A ) ;
        V[i].T = ( X - V[i].D ) / L ;
        maxi = max ( maxi, V[i].T ) ;
    }
    sort ( V + 1, V + N + 1, greater < pair < int, pair < int, int > > > () ) ;
}

void solve ( void ) {
    long long rez = 0 ;

    for ( int i = 1; maxi >= 0; --maxi ) {
        for ( ; maxi == V[i].T ; H.push ( V[i++].A ) ) ;
        if ( ! H.empty () ) {
            rez += H.top () ;
            H.pop () ;
        }
    }

    fprintf ( fopen ( FOU, "w" ) , "%lld", rez ) ;
}

int main ( void ) {
    read_data (), solve () ;
}