 # Round Robin Ranks

what is g indicating in this code ?please explain working of this code?

`````` ll n,k;
cin >> n >> k;
ll max = ((n) * (n-1)) /2;
ll wk = ((n-k) * (n-k-1))/2;
ll g = (max - wk)/k;
ll ans = (g) * 2;
cout << ans << "\n";
``````

regards

Max indicates total number of wins in the tournament ( which is also total number of matches played). The objective is to take all possible wins from teams less than k th place
and all possible wins between teams 1st place to k th place and distribute them equally among top K teams. This value is the same as ((total number of matches) - (no. of matches that bottom n-k teams played against each other)) (note that number of matches = number of wins). To divide equally between k teams we have divided this value by k then multiplied by 2 because each win gives 2 points.

1 Like

How this value is the same as ((total number of matches) - (no. of matches that bottom n-k teams played against each other))

Sorry to be so dump but I am still failing to understand this line

Total no. of matches=(no. of matches top K teams played among themselves)+(no. of matches rest of the (n-k) teams played among themselves)+(no. of matches top K teams played with the rest (n-k) teams). (n(n-1))/2=((k(k-1))/2)+((n-k)(n-k-1))/2)+(k(n-k))

1 Like