Hello everyone can you please tell my why we divide elements as n/m and n/m + 1 in order to minimize the pair of friends. Please help i have my exam tomorrow https://codeforces.me/contest/478/submission/77214745
# | User | Rating |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | nor | 152 |
Hello everyone can you please tell my why we divide elements as n/m and n/m + 1 in order to minimize the pair of friends. Please help i have my exam tomorrow https://codeforces.me/contest/478/submission/77214745
Name |
---|
Hello there. I cannot understand what you don't really understand so I will just explain the solution of this problem. If we want to minimize the number of total friends, we will uniformly distribute players along the teams. So, answer will be equal to n/m. Now after we distributed the players, we want to calculate number of friends in each team. Because the whole team is friends with each other, we need to find the number of pairs. For example, if the team has 5 members, the first is friend with the other four. The second is friend with the other three(notice that, we will not count his friend with the first as we already counted their friendship before). With that, we want an equation to calculate for us 4+3+2+1 efficiently. We can easily use $$$(n*(n-1)/2)$$$ which calculates $$$\sum_{x=1}^{n} x$$$ in O(1). Notice that there is something missing. What if we could not fully distribute the players that all the teams have the same amount of players? We should check how many players will remain. So first, we will calculate the number of teams that have n/m players separately, and calculate that will have n/m+1 using the summation formula rule. We can know the remaining players by using n%m Now, after we got the minimum number of pairs of friends, let me explain the maximum. The maximum is a lot easier. A team must consist of at least a player. So we are going to make a new variable called result and that variable will be equal to: n-m+1. We will subtract the number of teams from n and then add 1 as we will use only 1 team to make the maximum number of pairs of friends. We will use that result and the actual maximum answer will be equal to: $$$result*(result-1)/2$$$. I hope this explanation helped! If you have any questions, ask me.
thank you ahmadsm2005
You're welcome!