Cod sursa(job #1050797)

Utilizator rebound212Mihnea Savu rebound212 Data 9 decembrie 2013 10:01:41
Problema Lupul Urias si Rau Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <cstdio>
#include <set>
#include <vector>
#include <algorithm>
#define s second
#define f first
using namespace std;
multiset <int> h;
vector <pair<int,int> > a;
pair <int,int> o;
multiset <int>::iterator it;

using namespace std;
int x,i,sol,l,j,poz,lan,n,timp;
int main()
{
    freopen("lupu.in","r",stdin);
    freopen("lupu.out","w",stdout);
    scanf("%d %d %d",&n,&x,&l);
    for(i=1; i<=n; i++)
    {
        scanf("%d %d",&poz,&lan);
        if(poz<=x)
        {
            timp=(x-poz)/l+1;
            a.push_back(make_pair(timp,lan));
        }
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
   o=*(a.begin());
   j=o.f;
    i=0;
    for(i=j; i>=1; i--)
    {
        if(a[i].f==i)
        {

            h.insert(a[i].s);
        }
        else{
       it=h.end();
        it--;
        sol+=*it;
        h.erase(it);
        }
    }

    return 0;
}