Cod sursa(job #1106716)

Utilizator marinutzacatana marina marinutza Data 13 februarie 2014 08:22:13
Problema Lupul Urias si Rau Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include<fstream>
using namespace std;
#include<algorithm>
#include<set>
ifstream f("lupu.in");
ofstream g("lupu.out");
#define nmax 100010
long long sol;
int n,x,d;
struct elem
{
    int ln;
    int x;
} oi[nmax];
struct cmp
{
     bool operator()(const int &a,const int &b)
     {
         return a>b;
     }
};
bool comp (elem a,elem b)
{
    return a.x>b.x;
};
multiset <int,cmp> h;
multiset <int,cmp> h_mic;
int main()
{
    f>>n>>x>>d;
    for(int i=1;i<=n;i++)
    {
        f>>oi[i].x>>oi[i].ln;
        h.insert(oi[i].ln);
        if(oi[i].x>x-d && oi[i].x<=d)
            h_mic.insert(oi[i].ln);
    }
    sort(oi+1,oi+n+1,comp);
    int k=1;
    while(x-d>0)
    {
        if(*h.begin()==*h_mic.begin())
        sol+=*h.begin();
        else
        sol+=*h_mic.begin();
        h_mic.clear();
        while(oi[k].x>x-d)
            h.erase(h.find(oi[k++].ln));
        x-=d;
    }
    g<<sol<<'\n';
    return 0;
}