Pagini recente » Cod sursa (job #806314) | Cod sursa (job #1866744) | Cod sursa (job #2279268) | Cod sursa (job #1269736) | Cod sursa (job #2443943)
#include <iostream>
#include <fstream>
#include <utility>
#include <algorithm>
#include <vector>
using namespace std;
ifstream fin("lupu.in");
ofstream fout("lupu.out");
bool sortbysec(const pair<int,int> &a,
const pair<int,int> &b)
{
return (a.first > b.first);
}
int main(){
int n, x, l, d, lana;
fin >> n >> x >> l;
vector<pair<int, int>> v;
for(int i = 1; i <= n; i++){
fin >> d >> lana;
v.push_back(make_pair(d, lana));
}
sort(v.begin(), v.end(), sortbysec);
int copie = v[n].first;
int pas = 0;
while(copie <= x){
pas++;
copie += l;
}
int max = 0;
int nr = 1;
int S = 0;
while(pas){
max = 0;
for(int i = nr; i <= n; i++){
if(v[i].first + l > x){
nr++;
if(v[i].second > max){
max = v[i].second;
}
}else{
continue;
}
}
S += max;
pas--;
}
fout << S <<" ";
}