Cod sursa(job #2813470)

Utilizator Antonia_onisoruantonia onisoru Antonia_onisoru Data 6 decembrie 2021 18:44:25
Problema Lupul Urias si Rau Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <iostream>
#include <fstream>
#include <queue>
#include <algorithm>

using namespace std;

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

const int MAXN = 100000;

struct Sheep{
  int poz, val;
};

Sheep sheep[MAXN];

priority_queue<int> heap;

void inser( int val ){
  heap.push(val);
}

int myTop(){
  int top;

  top = 0;
  if( !heap.empty() ){
    top = heap.top();

    heap.pop();
  }

  return top;
}

bool cmp( const Sheep &a, const Sheep &b ){
  return a.poz < b.poz;
}

int main()
{
    long long totalLana = 0;
    int n, x, l, i, d;
    in>>n>>x>>l;
    for( i = 0; i < n; i++ ){
      in>>sheep[i].poz>>sheep[i].val;
    }

    sort(sheep, sheep + n, cmp);

    d = x % l;
    totalLana = 0;
    i = 0;
    while(d <= x ){
      while( i <= n && sheep[i].poz <= d ){
        inser(sheep[i++].val);
      }

      totalLana+=myTop();
      d+=l;
    }

    out<<totalLana;
    return 0;
}