Cod sursa(job #3243677)

Utilizator RosheRadutu Robert Roshe Data 20 septembrie 2024 12:53:25
Problema Lupul Urias si Rau Scor 8
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <iostream>
#include <queue>
#include <fstream>
#include <utility>

using namespace std;

ifstream in("lupu.in");
ofstream out("lupu.out");

pair<unsigned int, unsigned int> H;
priority_queue<pair<unsigned int, unsigned int>, vector<pair<unsigned int,unsigned int> > > pq;

bool operator<(const pair<unsigned int, unsigned int>& a, const pair<unsigned int, unsigned int>& b){
  if (a.first < b.first) return true;
  if (a.first > b.first) return false;
  if(a.second < b.second) return true;
  return false;
}

int main(){
  unsigned int N, X, L;
  in >> N >> X >> L;
  for(int i = 0; i<N; i++){
    unsigned int D, F;
    in >> D >> F;
    H = make_pair(F, D);
    pq.push(H);
  }
  long long total = 0;
  unsigned int step = 0;
  while(pq.empty() == false){
    //cout << pq.top().first << " " << pq.top().second << endl;
    unsigned int add = L * step;
    if(pq.top().second + add <= X){
      total+=pq.top().first;
      step++;
    }  
    pq.pop();
  }
  out << total;
}