fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void swap(int *a, int *b){
  5. int tmp;
  6. tmp = *a;
  7. *a = *b;
  8. *b = tmp;
  9. }
  10.  
  11. void mySort(int a[], int n){
  12. int i,j;
  13. for(i=0;i<n-1;i++){
  14. for(j=n-1;j>i;j--){
  15. if(a[j]>a[j-1])
  16. swap(&a[j],&a[j-1]);
  17. }
  18. }
  19. }
  20.  
  21. int solve(){
  22. int ret = 0;
  23. int n,q,i,j,x;
  24. int *m;
  25. scanf("%d %d",&n,&q);
  26. m = (int*)malloc(sizeof(int)*n*q);
  27. if(m==NULL){
  28. printf("ERROR\n");
  29. return -1;
  30. }
  31. for(i=0;i<n;i++){
  32. scanf("%d",&x);
  33. ret += x;
  34. for(j=0;j<q;j++){
  35. x = (x+1)/2;
  36. m[i*q+j] = x;
  37. }
  38. }
  39. mySort(m,n*q);
  40. for(i=0;i<q;i++){
  41. ret -= m[i];
  42. }
  43. free(m);
  44. return ret;
  45. }
  46.  
  47. //メイン関数はいじらなくて良い
  48. int main(void){
  49. printf("%d\n",solve());
  50. return 0;
  51. }
  52.  
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
0