Cod sursa(job #2923894)

Utilizator SeracovanuEdwardSeracovanu Edward SeracovanuEdward Data 20 septembrie 2022 18:06:08
Problema Lupul Urias si Rau Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <bits/stdc++.h>

using namespace std;

int const nmax = 1e5 + 5;

int n , x , l , r;

pair <int,int> A[nmax];

bool cmp(pair <int,int> a,pair<int,int> b){
return a.second < b.second;
}

int main()
{
    freopen("lupu.in" , "r" , stdin);
    freopen("lupu.out" , "w" ,stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n >> x >> l;
    for(int i = 1;i <= n; ++i){
        cin >> A[i].second >> A[i].first;
        A[i].second = (x - A[i].second) / l + 1;
    }
    sort(A + 1 ,A + 1 + n , cmp);
   // for(int i = 1;i <= n; ++i)
    //    cout << A[i].first << " " << A[i].second << "\n";
    priority_queue <int> q;
    int curr = A[n].second;
    int i = n;
    int ans = 0;
    while(curr && i){
        while(A[i].second == curr){
            q.push(A[i].first);
            --i;
        }
    if(!q.empty()){
        ans += q.top();
        q.pop();
    }
    --curr;
    }
    cout << ans;
}