Redaksiya
Let represent the number of passengers in the first, second and third minibuses respectively. For the number of passengers in minibuses to be the equal after the transfer, the sum must be divisible by .
Let be the number of passengers that should be in each minibus after the transfer. Then it is necessary to transfer from each minibus a certain number of passengers so that exactly passengers remain in each. This tranfer is only possible if a minibus initially contains more than passengers. For example, if , then passengers should be transferred from the first minibus. Similarly, passengers should be transferred from the second minibus (if ), and passengers from the third minibus (if ).
Algorithm realization
Read the input data.
scanf("%d %d %d",&a,&b,&c);
If the total number of people is not divisible by , then print IMPOSSIBLE.
if((a + b + c) % 3 != 0) puts("IMPOSSIBLE"); else { res = 0;
Compute the number of people in minibuses after the transfer.
d = (a + b + c) / 3;
In the variable count the number of transfered people.
if (a > d) res += a - d; if (b > d) res += b - d; if (c > d) res += c - d;
Print the answer.
printf("%d\n",res); }
Python realization
Read the input data.
a, b, c = map(int, input().split())
If the total number of people is not divisible by , then print IMPOSSIBLE.
if (a + b + c) % 3 != 0: print("IMPOSSIBLE") else: res = 0
Compute the number of people in minibuses after the transfer.
d = (a + b + c) // 3
In the variable count the number of transfered people.
if a > d: res += a – d if b > d: res += b – d if c > d: res += c – d
Print the answer.
print(res)