Cod sursa(job #2418096)

Utilizator TheNextGenerationAyy LMAO TheNextGeneration Data 3 mai 2019 16:21:33
Problema Lupul Urias si Rau Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <bits/stdc++.h>
using namespace std;
ifstream in("lupu.in");
ofstream out("lupu.out");
const int N = 1e5+5;
pair<int,int> v[N];
priority_queue<int> q;
int k;
int main()
{
    int n,x,l;
    long long s = 0;
    in >> n >> x >> l;
    for (int i = 1; i<=n; i++)
    {
        int a,d;
        in >> d >> a;
        if (d<=x)
            v[++k] = {(x-d)/l+1,a};
    }
    sort(v+1,v+k+1);
    int t = v[k].first;
    for (int pas = t; pas>=1; pas--)
    {
        while (k>=1 && v[k].first == pas)
        {
            q.push(v[k].second);
            k--;
        }
        if (!q.empty())
        {
            s+=q.top();
            q.pop();
        }
    }
    out << s;
}