Cod sursa(job #3150870)

Utilizator SSKMFSS KMF SSKMF Data 18 septembrie 2023 20:09:53
Problema Lupul Urias si Rau Scor 16
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.16 kb
#include <fstream>
#include <algorithm>
using namespace std;

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

pair <int , int> optiuni[100001];

int main ()
{
    int lungime , limita , termen;
    cin >> lungime >> limita >> termen;

    for (int indice = 1 ; indice <= lungime ; indice++)
    { 
        cin >> optiuni[indice].first >> optiuni[indice].second; 

        if (optiuni[indice].first <= limita)
            optiuni[indice].first = (limita - optiuni[indice].first) / termen; 
        else
            { indice--; lungime--; }
    }

    sort(optiuni + 1 , optiuni + lungime + 1 , [] (pair <int , int> optiune_1 , pair <int , int> optiune_2) -> bool {
        if (optiune_1.first != optiune_2.first)
            return optiune_1.first < optiune_2.first;

        return optiune_1.second > optiune_2.second;
    });

    long long maxim = 0;
    for (int indice = 1 ; indice <= lungime ; indice++)
    {
        maxim += optiuni[indice].second;
        while (indice < lungime && optiuni[indice + 1].first == optiuni[indice].first)
            indice++;
    }

    cout << maxim;
    cout.close(); cin.close();
    return 0;
}