Cod sursa(job #3282473)

Utilizator mateistefan11matei stefan mateistefan11 Data 5 martie 2025 19:37:23
Problema Lupul Urias si Rau Scor 8
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <bits/stdc++.h>
#define oo 1000000007
using namespace std;
ifstream fin("lupu.in");
ofstream fout("lupu.out");
/**
10 6 2
1 13
4 14
4 3
6 7
0 7
5 16
3 16
4 10
4 18
3 16

4 18
*/
priority_queue<pair<int,int>> q;
int n,x,l;
int main()
{
    ios_base::sync_with_stdio(0);
    fin.tie(0);
    fout.tie(0);
    int i,j,k;
    fin >> n >> x >> l;
    for(k = 1; k <= n; k++)
    {
        fin >> i >> j;
        if(i <= x)
            q.push({j, i});
    }
    int ans = 0, length = 0;
    while(!q.empty())
    {
        auto t = q.top();
        q.pop();
        if(t.second + length <= x)
        {
            length += l;
            ans += t.first;
        }
    }
    fout << ans;
    return 0;
}