# The Trip

### From Progteam

Sorter: | kerry |
---|---|

Source: | Unknown |

Link: | http://acm.pku.edu.cn/JudgeOnline/problem?id=2646 |

**The Trip** is problem number 2646 on the Peking University ACM
site.

C answer. Float for the values leads to arithmetic errors, so you need a double.

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> int main() { long double current, total, avg, upper_total, answer, input[1001]; int i, j, num, upper_num; scanf("%d", &num); while (num !=0) { current=0.0; total=0.0; avg=0.0; answer=0.0; upper_total=0.0; upper_num=0; for(i=0;i<num;i++) { scanf("%Lf", ¤t); input[i]=current; total += current; } avg = (total/num)*100; avg = floor(avg); avg = (avg/100); for(i=0;i<num;i++) { if (input[i]<avg) answer+=(avg-input[i]); else if (input[i]>avg) { upper_total+=(input[i]-avg); upper_num++; } } if ((total - avg*num) > (upper_num*0.01)) { answer += (total-avg*num-upper_num*0.01); } printf("$%.2Lf\n", answer); scanf("%d", &num); } }