Cod sursa(job #2046385)

Utilizator cella.florescuCella Florescu cella.florescu Data 23 octombrie 2017 19:16:49
Problema Lupul Urias si Rau Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <bits/stdc++.h>

using namespace std;

vector <pair <int, int>> v;
priority_queue <int> pq;

int main()
{
    int n, x, l;
    ifstream fin("lupu.in");
    fin >> n >> x >> l;
    for (int i = 0; i < n; ++i) {
      int d, a;
      fin >> d >> a;
      if (d <= x)
        v.push_back({(x - d) / l, a});
    }
    fin.close();
    sort(v.rbegin(), v.rend());
    long long ans = 0LL;
    int ind = 0;
    for (int i = n; i >= 0; --i) {
      while (ind < n && v[ind].first == i)
        pq.push(v[ind++].second);
      if (pq.empty() == false) {
        ans += pq.top();
        pq.pop();
      }
    }
    ofstream fout("lupu.out");
    fout << ans;
    fout.close();
    return 0;
}