Pagini recente » Cod sursa (job #833074) | Cod sursa (job #990798) | Cod sursa (job #1643886) | Cod sursa (job #3149314) | Cod sursa (job #3150870)
#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;
}