Pagini recente » Cod sursa (job #2967787) | Cod sursa (job #191066) | Cod sursa (job #2662216) | Cod sursa (job #597167) | Cod sursa (job #3141997)
#include <fstream>
#include <algorithm>
#define dist first
#define wool second
using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");
const int nmax = 100005;
int prey, scared, n, sumi;
pair<int, int> A[nmax];
bool cmp(pair<int, int> x, pair<int, int> y)
{
if(x.dist != y.dist)
return (x.dist < y.dist);
else
return (x.wool > y.wool);
}
int main()
{
f >> n >> prey >> scared;
for(int i = 1; i <= n; i ++)
{
int x;
f >> x >> A[i].wool;
int nr = 0;
while(x <= prey)
{
x += scared;
nr ++;
}
A[i].dist = nr;
}
sort(A + 1, A + n + 1, cmp);
int run = 0;
for(int i = 1; i <= n; i ++)
if(A[i].dist - run)
{
sumi += A[i].wool;
run ++;
}
g << sumi;
return 0;
}