Cod sursa(job #1044381)

Utilizator Athena99Anghel Anca Athena99 Data 29 noiembrie 2013 18:51:48
Problema Lupul Urias si Rau Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <fstream>
#include <algorithm>

using namespace std;

ifstream fin("lupu.in");
ofstream fout("lupu.out");

const int nmax= 100000;

struct str {
    int x, y;
} v[nmax+1];

bool comp( str a, str b ) {
    if ( a.y==b.y ) {
        return a.x>b.x;
    } else {
        return a.y>b.y;
    }
}

bool u[nmax+1];

int main(  ) {
    int n, x, l;
    fin>>n>>x>>l;
    for ( int i= 1; i<=n; ++i ) {
        fin>>v[i].x>>v[i].y;
        v[i].x= (x-v[i].x+l)/l;
    }
    sort(v+1, v+n+1, comp);
    
    int k= 1, sol= 0;
    for ( int i= 1; i<=n; ++i ) {
        if ( v[i].x>=k ) {
            for ( int j= v[i].x; j>=1; --j ) {
                if ( u[j]==0 ) {
                    u[j]= 1;
                    sol+= v[i].y;
                    ++k;
                    j= 0;
                }
            }
        }
    }

    fout<<sol<<"\n";

    return 0;
}