Cod sursa(job #2959989)

Utilizator Luka77Anastase Luca George Luka77 Data 3 ianuarie 2023 13:14:43
Problema Lupul Urias si Rau Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <bits/stdc++.h>
using namespace std;

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

/// GLOBAL VARIABLES
int n, x, l;
vector<pair<int,int>>v;

inline bool compare(pair<int,int>x, pair<int,int>y)
{
    if(x.second == y.second)
        return x.first > y.first;
    return x.second < y.second;
}

/// SOLUTION
inline void solve()
{
    int ans = 0;
    sort(v.rbegin(), v.rend(), compare);
    for(int i = 0; i < v.size(); ++ i)
    {
        if(x >= v[i].first)
            ans += v[i].second, x-=l;
    }
    fout << ans;
}

/// READING THE INPUT
int main()
{
    ios::sync_with_stdio(false);
    fin.tie(NULL);
    fout.tie(NULL);
    fin >> n >> x >> l;
    for(int i = 1; i <= n; ++ i)
    {
        int n1, n2;
        fin >> n1 >> n2;
        v.push_back({n1,n2});
    }
    solve();
}