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