Cod sursa(job #3285845)

Utilizator ana.veronica13Ana Veronica Draghici ana.veronica13 Data 13 martie 2025 15:12:28
Problema Lupul Urias si Rau Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <bits/stdc++.h>

using namespace std;

#define MAX_N 100001

struct oaie{
  int d, lana, t;
};

oaie o[MAX_N];

int cmp( oaie a, oaie b ){
  if( a.t == b.t )
    return a.lana > b.lana;
  return a.t > b.t;
}

priority_queue<int> pq;

int main(){
  ifstream cin( "lupu.in" );
  ofstream cout( "lupu.out" );
  int n, i, x, l, timp;
  long long s;
  cin >> n >> x >> l;
  for( i = 1; i <= n; i++ ){
    cin >> o[i].d >> o[i].lana;
    o[i].t = ( x - o[i].d ) / l;
  }
  sort( o + 1, o + n + 1, cmp );
  i = 1;
  s = 0;
  for( timp = x / l; timp >= 0; timp-- ){
    while( i <= n && o[i].t == timp ){
      pq.push(o[i].lana);
      i++;
    }
    if( !pq.empty() ){
      s += pq.top();
      pq.pop();
    }
  }
  cout << s;
    return 0;
}