QM6P5B editorial

PROBLEM LINK:

Practice

Contest

Author: Chandan Boruah

Tester: Chandan Boruah

Editorialist: Chandan Boruah

DIFFICULTY:

EASY

PREREQUISITES:

Sorting (bubble).

PROBLEM:

Given few teams with scores and groups. Find what happens to the group winners when two teams swap groups.

QUICK EXPLANATION:

Swap the two teams in the groups with the scores and then sort the teams in the groups.

EXPLANATION:

Swap the two teams in the groups along with their scores. Do a bubble sort on the groups, swap positions if scores are in ascending and only if the groups of the teams are same. Since same name groups appear contigously the groups won’t mix and everything would be sorted. Then print the winners of each group.

AUTHOR’S SOLUTION IN C#:

using System;
class some
{
	public static void Main()
	{
		int n=int.Parse(Console.ReadLine());
		for(int t=0;t<n;t++)
		{
			string[]ss=Console.ReadLine().Split();
			int a=int.Parse(ss[0]);
			int b=int.Parse(ss[1]);
			string[]names=new string[a*b];
			string[]teams=new string[a*b];
			int[]scores=new int[a*b];
			for(int i=0;i<names.Length;i++)
			{
				ss=Console.ReadLine().Split();
				names*=ss[0];
				teams*=ss[1];
				scores*=int.Parse(ss[2]);
			}
			ss=Console.ReadLine().Split();
			string aa=ss[0];
			string bb=ss[1];
			int indA=Array.IndexOf(names,aa);
			int indB=Array.IndexOf(names,bb);
			names[indA]=bb;
			names[indB]=aa;
			int temp=scores[indA];
			scores[indA]=scores[indB];
			scores[indB]=temp;
			for(int i=0;i<scores.Length;i++)
			{
				for(int j=0;j<scores.Length-1;j++)
				{
					if(scores[j]<scores[j+1] && teams[j]==teams[j+1])
					{
						int tt=scores[j];
						scores[j]=scores[j+1];
						scores[j+1]=tt;
						string k1=names[j];
						names[j]=names[j+1];
						names[j+1]=k1;
					}
				}
			}
			for(int i=0;i<teams.Length;i++)
			{
				if(i%b==0)
				Console.WriteLine(names*);
			}
		}
	}
}