Cod sursa(job #2961485)

Utilizator AndreiMargaritMargarit Andrei AndreiMargarit Data 6 ianuarie 2023 16:07:39
Problema Lupul Urias si Rau Scor 64
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.1 kb
#include <bits/stdc++.h>

using namespace std;

ifstream f("lupu.in");
ofstream g("lupu.out");

multiset <pair<int,int>>oi;
multiset <int> alegeri;

int main()
{int n,x,l,i,dinit,lana,tmax,timp,max1,s;
    f>>n>>x>>l;
    for(i=1;i<=n;i++)
    {
        f>>dinit>>lana;
        tmax=(x-dinit)/l;
        oi.insert({tmax,lana});
    }
    tmax=x/l;
    s=0; i=0;
    auto it=oi.end();
    it--;
    while(tmax>=0)
    {
        while(it->first==tmax)
        {
            alegeri.insert(it->second);
            if(!oi.empty())
            {
                it--;
            }
        }
        tmax--;
        auto it2=alegeri.end();
        if(!alegeri.empty())
        {
            it2--;
        }
        max1=*it2;
        s=s+max1;
        alegeri.erase(alegeri.find(max1));
    }
    /*
    for(i=0;i<=tmax+1;i++)
    {
        max1=0;
        while(it->first==i)
        {
            if(it->second>max1)
            {
                max1=it->second;
            }
            it++;
        }
        s=s+max1;
    }*/
    g<<s<<'\n';
    return 0;
}