Cod sursa(job #1107746)

Utilizator marinutzacatana marina marinutza Data 14 februarie 2014 11:20:41
Problema Lupul Urias si Rau Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 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;
int main()
{
    f>>n>>x>>d;
    for(int i=1;i<=n;i++)
        f>>oi[i].x>>oi[i].ln;
    sort(oi+1,oi+1+n,comp);
    int k=0;
    for(int i=1;oi[i].x<=x;i++)
    {
    	if((float)oi[i].x/d<=(float)k)
    		h.insert(oi[i].ln);
    	else
    	{
    		sol+=*h.begin();
    		h.erase(*h.begin());
    		k++;
    	}
    }
    g<<sol<<'\n';
    return 0;
}