You are on page 1of 2

/*2025.

Line Fighting
Time limit: 1.0 second
Memory limit: 64 MB
Boxing, karate, sambo� The audience is sick of classic combat sports.
That is why a popular sports channel launches a new competition format based on the
traditional
Russian entertainment called line fighting. There can be from 2 to k teams taking
part in a competition,
and there are n fighters altogether in all the teams. Before the competition
starts, the fighters are divided into teams:
each fighter becomes a member of exactly one team. Two fighters fight each other if
they are members of different teams
. The organizers believe that the more the number of fights between fighters, the
higher the popularity of a competition will be.
Help the organizers to distribute fighters between teams so as to maximize the
number of fights and output this number.
Input
The first line contains the number of tests T (1 = T = 10). In each of the
following T lines you are given a test:
integers n and k separated with a space (2 = k = n = 104).
Output
For each test output the answer (one integer) in a separate line.

*/

#include <iostream>

using namespace std;

class comptetion {
private:
int lines;
int fighter;
int teams;
public:
void setline(int a)
{
lines = a;
}
void setval(int b, int c)
{

fighter = b;
teams = c;
}
int getoutput(int n, int k) {

int *a;
a = new int[k];
int mode = n % k;
int player = n / k;

for (int i = 0; i < mode; i++) {


a[i] = player + 1;
}
for (int i = mode; i < k; i++) {
a[i] = player;
}
int answer = 0;
for (int i = 0; i < k - 1; i++) {
for (int j = i + 1; j < k; j++) {
answer += a[i] * a[j];
}
}
return answer;
}
};
void main()
{
comptetion c;
int line, n, k;
cout << "Enter the lines of comptetion \n";
cin >> line;
c.setline(line);
for (int i = 0; i < line; i++) {
cout << "Enter the fighter player \n";
cin >> n;
cout<<"Enter the teams greater than 2\n";
cin >> k;
while (k < 2)
{
cout << "invalid Enter again \n";
cin >> k;
}

c.setval(n, k);
cout<<" output : "<< c.getoutput(n, k)<<endl;
}
system("pause");
}

You might also like