Cod sursa(job #2306652)

Utilizator Carol_LucaCarol Luca Carol_Luca Data 22 decembrie 2018 18:15:46
Problema Lupul Urias si Rau Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <bits/stdc++.h>



using namespace std;



FILE *fin = fopen ("lupu.in", "r"), *fout = fopen ("lupu.out", "w");



const int MAXN = 1e5;



pair <int, int> a[MAXN + 1];



priority_queue <int> heap;



int main() {

  int n, x, l, i, j, d;

  long long sol;

  fscanf (fin, "%d%d%d", &n, &x, &l);

  for (i = 1; i <= n; i++) {

    fscanf (fin, "%d%d", &a[i].first, &a[i].second);

  }

  sort (a + 1, a + n + 1);

  j = 1;

  sol = 0;

  for (d = 0; d <= x; d = d + l) {

    while (j <= n && a[j].first <= d) {

      heap.push (a[j++].second);

    }

    if (heap.empty () == false) {

      sol = sol + heap.top ();

      heap.pop ();

    }

  }

  fprintf (fout, "%lld\n", sol);

  fclose (fin);

  fclose (fout);

  return 0;

}