Min and max pairs between teams

http://codeforces.com/problemset/problem/478/B

The link above is the question.

I was able to get the max pairs easily but I am struggling to calculate the minimum pairs. Can someone help me out ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <bits/stdc++.h>


#define fl(n) for(int i = 0; i < n; i++)

#define ll   long long
#define nl   endl
#define pb   push_back
#define mp   make_pair
#define PII  pair<int,int>

#define EPS  1e-9
#define INF  1e9


using namespace std;

ll pairs(ll x){
    return x*(x-1)/2;
}

int main(){

    ll n , m;
    cin >> n >> m;

    ll mx = pairs(n-(m-1));
    ll mn =  // ? :/


    return 0;
}


Thanks.
Max is found when all of the "extra" players are all on the same team. You have the solution to that.

Min is found when all of the players are spread as evenly as possible across all of the teams. So, if the number of players is evenly divisible by the number of teams, all teams will have n/m players. If the number is not evenly divisible, the remainder (n % m) is the number of teams that have 1 additional player.

After that, just use pairs() to calculate the number of pairs for each group size and then multiply and add to get your answer.
Topic archived. No new replies allowed.