Cod sursa(job #1050788)

Utilizator OnimushaLordTiberiu Copaciu OnimushaLord Data 9 decembrie 2013 09:50:29
Problema Lupul Urias si Rau Scor 32
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
# include <cstdio>
# include <set>
# include <algorithm>
# define MAXN 100010


using namespace std;

int t,l,n,x,X,i,k,S;
struct oi
{
    int t,l;
};
multiset < int > h;
multiset < int > :: iterator it;
oi a[MAXN],b;
bool cmp(oi a, oi b)
{
    return a.t>b.t;
}
int main()
{
    freopen("lupu.in", "r", stdin);
    freopen("lupu.out", "w", stdout);
    scanf("%d %d %d\n", &n, &l, &x);
    for(i=1; i<=n; ++i)
    {
        scanf("%d %d\n", &X, &a[i].l);
        a[i].t=(l-X)/x+1;
    }
    sort(a+1, a+n+1, cmp);
    i=1;
    while(a[i].t)
    {
        k=i;
        while(a[k].t==a[i].t)
        {
            h.insert(a[k].l);
            k++;
        }
        it=h.end();
        it--;
        S+=*it;
        h.erase(it);
        i=k;
    }
    printf("%d\n", S);
    fclose(stdin);
    fclose(stdout);
    return 0;
}