Cod sursa(job #3372990)

Utilizator Cezar2009Cezar Mihai Titihazan Cezar2009 Data 5 noiembrie 2026 18:56:59
Problema Lupul Urias si Rau Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.24 kb
// https://www.infoarena.ro/problema/lupu

#include <functional>
#include <queue>
#include <vector>
#pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC optimize("O3,unroll-loops")
#pragma GCC target(                                                            \
    "avx512f,avx512bw,avx512dq,avx512cd,avx512vl,bmi,bmi2,lzcnt,popcnt,fma")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt,fma")

// #define _USE_MATH_DEFINES

#include <bits/stdc++.h>

using namespace std;

using int64 = int64_t;
using uint64 = uint64_t;
using int32 = int32_t;
using uint32 = uint32_t;
using int16 = int16_t;
using uint16 = uint16_t;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define all(x) (x).begin(), (x).end()
#define allg(x) (x).begin(), (x).end(), greater<int>()
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define rfor(i, st, dr) for (auto i = (st); i <= (dr); ++i)
#define for0(i, n) for (auto i = 0; i < (n); ++i)
#define rfor0(i, n) for (auto i = (n) - 1; i >= 0; --i)
#define for1(i, n) for (auto i = 1; i <= (n); ++i)
#define rfor1(i, n) for (auto i = (n); i >= 1; --i)
#define foreach(x, a) for (auto &x : a)
#define cforeach(x, a) for (const auto &x : a)
#define ft first
#define sd second
#define cendl cout << "\n"
#define fendl fout << "\n"
#define FASTIO                                                                 \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(nullptr);

#define int int64
fstream fin("lupu.in");
ofstream fout("lupu.out");

// FILE* fin = fopen("", "r");
// FILE* fout = fopen("", "w");

const int NRMAX = 100000;

pii v[NRMAX + 5];

int32 main() {
  // FASTIO;

  int n, x, l, rez = 0;
  int d, a;

  priority_queue<int, vector<int>, greater<int>> pq;

  fin >> n >> x >> l;

  for0(i, n) {
    fin >> d >> a;
    if (d > x) {
      continue;
    }

    int nr = (x - d) / l + 1;
    v[i] = {nr, a};
  }

  sort(v, v + n);

  for0(i, n) {
    // cout << v[i].ft << " " << v[i].sd << "\n";
    pq.push(v[i].sd);
    rez += v[i].sd;

    if (sz(pq) > v[i].ft) {
      rez -= pq.top();
      pq.pop();
    }
  }

  fout << rez << "\n";

  return 0;
}