Cod sursa(job #922978)

Utilizator paunmatei7FMI Paun Matei paunmatei7 Data 22 martie 2013 19:05:59
Problema Lupul Urias si Rau Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include<stdio.h>
#include<algorithm>
#include<vector>
#define d first
#define b second
#include<queue>
using namespace std;
pair <int , int>a[1001];
vector<int>mat[1001];
priority_queue<int>pq;
int n , x , l;
int main()
{
    freopen("lupu.in" , "r" , stdin);
    freopen("lupu.out" , "w" , stdout);
    scanf("%d %d %d" , &n , &x , &l);
    for (int i=1 ; i<=n ; ++i)
    {
        scanf("%d %d" , &a[i].d , &a[i].b);
        if(x >= a[i].d)
            mat[(x-a[i].d)/l+1].push_back(i);
    }
    int ans=0;
    for(int t=n ; t>=1 ; --t)
    {
        for(int i=0 ; i<mat[t].size() ; ++i)
            pq.push(a[mat[t][i]].b);
        if(! pq.empty())
        {
            ans+=pq.top();
            pq.pop();
        }
    }
    printf("%d" , ans);
    return 0;
}