Pagini recente » Cod sursa (job #1108489) | Cod sursa (job #2245831) | Cod sursa (job #2182597) | Cod sursa (job #415474) | Cod sursa (job #438648)
Cod sursa(job #438648)
#include <stdio.h>
02.#include <stdlib.h>
03.#include <string.h>
04.#define in "gutui.in"
05.#define out "gutui.out"
06.
07.typedef struct
08. {
09. int h;
10. int g;
11. int coef;
12. }pom;
13.int compare2(const void *a,const void *b)
14. {
15. pom *x,*y;
16. x=(pom*)a;
17. y=(pom*)b;
18. return -x->g + y->g ;
19. }
20.
21.int compare(const void* a,const void* b)
22. {
23. pom *x,*y;
24. x=(pom*)a;
25. y=(pom*)b;
26. if (x->coef != y->coef)
27. return x->coef-y->coef;
28. else
29. return -x->g+y->g;
30. }
31.
32.int main()
33. {
34. int j,n,i,max_height,up_height,sum=0,nr=0,*frei;
35. pom *gutui;
36. freopen(in,"r",stdin);
37. freopen(out,"w",stdout);
38. scanf("%d %d %d",&n,&max_height,&up_height);
39. gutui=(pom*)malloc(n*sizeof(pom));
40. for (i = 0; i < n; ++i)
41. {
42. scanf("%d %d",&gutui[i].h,&gutui[i].g);
43. gutui[i].coef=(max_height-gutui[i].h)/up_height+1;
44. if (nr < gutui[i].coef)
45. nr = gutui[i].coef;
46. if( gutui[i].h > max_height )
47. {
48. i--;
49. n--;
50. }
51. }
52. qsort(gutui,n,sizeof(pom),compare2);
53. frei = (int*)malloc(nr*sizeof(int));
54. memset(frei,0,(nr+1)*sizeof(int));
55. for (i = 0; i < nr; ++i)
56. {
57.
58. for ( j = gutui[i].coef ; j > 0; j--)
59. {
60. //printf("%d %d\n",j,frei[j]);
61. if (frei[j] == 0)
62. {
63. // printf("me:%d %d %d \n",gutui[i].h,gutui[i].g,gutui[i].coef);
64. sum += gutui[i].g;
65. frei[j] = 1;
66. break;
67. }
68. }
69. if (j == 0 && nr < n)
70. nr++;
71. }
72. printf("%d\n",sum);
73.
74. return 0;
75. }