fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void solve()
  5. {
  6. int x[3];
  7. cin >> x[0] >> x[1] >> x[2];
  8.  
  9.  
  10. double avg_d = (x[0] + x[1] + x[2]) / 3;
  11.  
  12. int avg = ceil(avg_d);
  13.  
  14. cout << "avg = "<<avg<<endl;
  15.  
  16. for (int i = 0; i < 3; i++)
  17. {
  18. if (x[i] > avg)
  19. x[i]--;
  20. else if (x[i] < avg)
  21. x[i]++;
  22. }
  23.  
  24. int ans = abs(x[0] - x[1]) + abs(x[0] - x[2]) + abs(x[1] - x[2]);
  25.  
  26. cout << ans << "\n"<<endl;
  27. }
  28.  
  29. int main()
  30. {
  31. ios_base::sync_with_stdio(false);
  32. cin.tie(0);
  33.  
  34. int t;
  35. cin >> t;
  36.  
  37. while (t--)
  38. {
  39. solve();
  40. }
  41. }
Success #stdin #stdout 0.01s 5288KB
stdin
50
52 49 46
49 47 52
52 49 49
44 45 51
46 47 47
47 48 46
49 44 46
43 44 43
52 49 45
46 48 49
45 52 52
50 51 47
49 52 52
47 47 44
43 44 46
43 50 51
48 51 46
47 46 43
46 47 45
43 49 46
48 47 50
44 43 43
48 51 47
43 44 47
43 46 46
49 44 52
51 45 50
51 47 51
46 51 46
49 46 44
49 44 47
48 51 43
47 51 50
50 51 48
51 50 50
52 50 44
52 48 52
43 50 44
48 44 52
52 49 52
50 47 45
47 47 52
44 49 49
51 46 49
52 50 52
45 45 49
44 50 44
51 46 51
46 46 48
43 48 51
stdout
avg = 49
8

avg = 49
6

avg = 50
2

avg = 46
10

avg = 46
0

avg = 47
0

avg = 46
6

avg = 43
0

avg = 48
10

avg = 47
2

avg = 49
10

avg = 49
4

avg = 51
2

avg = 46
2

avg = 44
2

avg = 48
12

avg = 48
6

avg = 45
4

avg = 46
0

avg = 46
8

avg = 48
2

avg = 43
0

avg = 48
4

avg = 44
4

avg = 45
2

avg = 48
12

avg = 48
8

avg = 49
4

avg = 47
6

avg = 46
6

avg = 46
6

avg = 47
12

avg = 49
4

avg = 49
2

avg = 50
0

avg = 48
12

avg = 50
4

avg = 45
10

avg = 48
12

avg = 51
2

avg = 47
6

avg = 48
6

avg = 47
6

avg = 48
6

avg = 51
0

avg = 46
4

avg = 46
8

avg = 49
6

avg = 46
2

avg = 47
12