#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//se scade din inaltimea maxima si se compara cu restul
typedef struct gutui_aux
{
int inaltime;
int valoare;
}
structuraGutui;
int comparator(const void* gutuie1, const void* gutuie2)
{
return (*(structuraGutui*)gutuie2).inaltime - (*(structuraGutui*)gutuie1).inaltime;
}
int max(int a, int b)
{
if (a > b) return a;
else return b;
}
//de trimis pointerul in locul vectorului
//CEVA E GRESIT AICI
int profit(structuraGutui* gutui, int i, int n, int inaltime, int pas)
{
if (inaltime <= 0 || i >= n)
return 0;
if (gutui[i].inaltime <= inaltime)
return max( (profit(gutui, i+1, n, inaltime - pas, pas) + gutui[i].valoare),
profit(gutui, i+1, n, inaltime, pas) );
else
return profit(gutui, i+1, n, inaltime, pas);
}
int main()
{
int fd1,fd2;
fd1=fopen("gutui.out", "w");
fd2=fopen("gutui.in", "r");
int numarGutui, height, step;
fscanf(fd2, "%i %i %i", &numarGutui, &height, &step);
//printf("Gutui: %i; Inaltime: %i; Step: %i \n", numarGutui, height, step);
//SAU STRUCTURA - > MAI NATURAL
structuraGutui gutui[numarGutui];
int i;
for (i = 0; i < numarGutui; i++)
fscanf(fd2, "%i %i ", &(gutui[i].inaltime), &(gutui[i].valoare));
qsort(gutui, numarGutui, sizeof(gutui[0]), comparator);
//for (i = 0; i < numarGutui; i++)
// printf( "%i %i \n", gutui[i].inaltime, gutui[i].valoare);
//printf("Profit: %i \n", profit(gutui, 0, numarGutui, height, step));
fprintf(fd1, "%i ", profit(gutui, 0, numarGutui, height, step));
fclose(fd2);
fclose(fd1);
return 0;
}