Pagini recente » Cod sursa (job #2148844) | Cod sursa (job #1486124) | Cod sursa (job #962312) | Cod sursa (job #2158370) | Cod sursa (job #1424625)
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
ifstream f("lupu.in");
int n, x, l;
f >> n >> x >> l;
vector<pair<int, int> > oi;
oi.resize(n);
int dist, ultima_tura = 0;
for(auto& oaie : oi){
f >> dist;
f >> oaie.second;
oaie.first = (x - dist)/l;
if(ultima_tura < oaie.first){
ultima_tura = oaie.first; } }
sort(begin(oi), end(oi), [](const pair<int, int>& lhs, const pair<int, int>& rhs){
return (lhs.first == rhs.first) ? (lhs.second > rhs.second) : lhs.first > rhs.first; });
int tura_curenta = ultima_tura, rez = 0;
for(const auto& x : oi){
if(tura_curenta < 0){
goto out; }
if(tura_curenta <= x.first){
rez += x.second;
--tura_curenta; } }
out:
ofstream g("lupu.out");
g << rez;
return 0; }