Cod sursa(job #3030578)

Utilizator Roxana_3Asavei Roxana Roxana_3 Data 17 martie 2023 18:50:38
Problema Lupul Urias si Rau Scor 68
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <bits/stdc++.h>
#define N 100000
using namespace std;

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


int n, x, l;
struct oaie
{
    int dist;
    int cant;
} a[N + 5];

long long cant_max;
multiset<int, greater<int> >ms;

void Citire()
{
    fin >> n >> x >> l;
    for(int i = 1; i <= n; ++i)
        fin >> a[i].dist >> a[i].cant;
}

inline bool comp(oaie x, oaie y)
{
    return x.dist < y.dist;
}


void Rezolvare()
{
   int r = x % l;
   int nr_pasi = x / l + 1;
   int i = 1;
   int j = 1;

   while(i <= nr_pasi)
   {
       while(a[j].dist <= r)
           ms.insert(a[j].cant), j++;

       if(!ms.empty())
          {cant_max += *ms.begin();
           ms.erase(ms.begin());
          }

       r += l;
       i++;

   }

   fout << cant_max;

}

int main()
{
    Citire();
    fin.close();
    sort(a + 1, a + n + 1, comp);
    Rezolvare();
    fout.close();

    return 0;
}