-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path207.cpp
47 lines (43 loc) · 897 Bytes
/
207.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
#include <stdlib.h>
typedef struct tagNode {
int k;
int b;
int i;
} node;
int cmp1(const void* a, const void* b) {
node* pa = (node*)a;
node* pb = (node*)b;
return pb->b - pa->b;
}
int cmp2(const void* a, const void* b) {
node* pa = (node*)a;
node* pb = (node*)b;
return pa->i - pb->i;
}
int main(void) {
int n, m, y;
scanf ("%d%d%d", &n, &m, &y);
int x[1000];
node h[1000];
int i, total = m;
for (i = 0; i < n; ++i) {
scanf ("%d", x+i);
h[i].k = m*x[i]/y;
h[i].b = m*x[i]%y;
h[i].i = i;
total -= h[i].k;
}
qsort(h, n, sizeof(h[0]), cmp1);
i = 0;
while (total--) {
h[i++].k++;
}
qsort(h, n, sizeof(h[0]), cmp2);
printf ("%d", h[0].k);
for (i = 1; i < n; ++i) {
printf (" %d", h[i].k);
}
printf ("\n");
return 0;
}