Pagini recente » Cod sursa (job #2607808) | Cod sursa (job #2640163) | Cod sursa (job #2479017) | Cod sursa (job #219108) | Cod sursa (job #440540)
Cod sursa(job #440540)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define file_in "gutui.in"
#define file_out "gutui.out"
int main()
{
int i, j, idx, N, other_N, H, U, max, *h, *w, *marked, *picked, solution;
freopen(file_in, "rt", stdin);
freopen(file_out, "wt", stdout);
scanf("%i %i %i", &N, &H, &U);
h = (int *)malloc(N*sizeof(int));
w = (int *)malloc(N*sizeof(int));
for(i = 0; i < N; i++)
scanf("%i %i", h+i, w+i);
marked = (int *)malloc(N*sizeof(int));
picked = (int *)malloc(N*sizeof(int));
solution = 0;
other_N = N;
memset(picked, 0, N*sizeof(int));
while(other_N > 0)
{
memset(marked, 0, N * sizeof(int));
for(i=0;i<N;i++)
if(h[i]+U*(other_N-N+1) > H)
marked[i] = 1;
max = 0;
idx = 0;
for(i=0;i<N;i++)
{
if((marked[i] == 1) && (picked[i] == 0) && (w[i] > max))
{
max = w[i];
idx = i;
}
}
if(max == 0)
{
for(i=0;i<N;i++)
if((picked[i] == 0) && (w[i] > max))
{
max = w[i];
idx = i;
}
}
picked[idx] = 1;
other_N--;
solution += max;
}
printf("%i", solution);
free(h);
free(w);
free(marked);
fclose(stdin);
fclose(stdout);
return 0;
}