ELEC_24 - Editorial

PROBLEM LINK:

Contest

Setter: aviroop_001

Tester: debrc , mishra_roshan

Editorialist: aviroop_001

DIFFICULTY:

Easy

PREREQUISITES:

Basic observations

PROBLEM:

The yearly elections, for the Class Representative, in which three candidates participated, namely John, Reese and Dwight, have recently ended. John received x votes, Reese received y votes, Dwight received z votes. For each of the candidates, calculate: How many votes should be added to “this” candidate’s vote so that he/she wins the CR election, i.e. the number of votes for “this” candidate should be strictly greater than the individual votes of the other two candidates.

Also, note that the added votes for any of the candidates do not affect the vote count when getting the answer for the other two candidates.

EXPLANATION

The aim here is to find the minimum number of votes that a candidate needs to win the elections. So, we must find the maximum votes out of the three candidates, and then calculate the vote’s difference one by one, that would give us the number of votes required to draw the elections. To win, we must have the majority votes, thus we must add 1.

SOLUTIONS:

Setter's Solution
C++
#include <bits/stdc++.h>
using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        int a,b,c;
        cin>>a>>b>>c;
        int x,y,z;
        int mx=max(a,max(b,c));
        
        if(a==b && a==c)
            cout<<1<<" "<<1<<" "<<1<<endl;
        else if(a==b && c==mx){
            cout<<mx-a+1<<" "<<mx-a+1<<" "<<0<<endl;
        }
        else if(a==c && b==mx){
            cout<<mx-a+1<<" "<<0<<" "<<mx-a+1<<endl;
        }
        else if(c==b && a==mx){
            cout<<0<<" "<<mx-b+1<<" "<<mx-b+1<<endl;
        }
        else if((a==b && mx==a)||(a==c && mx==c)||(b==c && c==mx)){
            x=(mx-a)==0?1:mx-a+1, y=(mx-b)==0?1:mx-b+1, z=(mx-c)==0?1:mx-c+1;
            cout<<x<<' '<<y<<' '<<z<<endl;
        }
        else{
            x=(mx-a)==0?0:mx-a+1, y=(mx-b)==0?0:mx-b+1, z=(mx-c)==0?0:mx-c+1;
            cout<<x<<" "<<y<<" "<<z<<endl;
        }
    }
    return 0;
}
Tester's Solution
Java
import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		while(t-->0){
		   int a=sc.nextInt();
		   int b=sc.nextInt();
		   int c=sc.nextInt();
        int x=0,y=0,z=0;
        int mx=(int)Math.max(a,(int)Math.max(b,c));
        
        if(a==b && a==c){
            System.out.println(1+" "+1+" "+1);
            continue;
        }
        else if(a==b && c==mx){
            System.out.println((mx-a+1)+" "+(mx-a+1)+" "+0);
            continue;
        }
        else if(a==c && b==mx){
            System.out.println((mx-a+1)+" "+ 0 +" "+(mx-a+1));
            continue;
        }
        else if(c==b && a==mx){
            System.out.println(0+" "+(mx-b+1)+" "+(mx-b+1));
            continue;
        }
        else if((a==b && mx==a)||(a==c && mx==c)||(b==c && c==mx)){
            x=(mx-a)==0?1:mx-a+1;
            y=(mx-b)==0?1:mx-b+1;
            z=(mx-c)==0?1:mx-c+1;
            System.out.println(x+" "+y+" "+z);
            continue;
        }
        else{
            x=(mx-a)==0?0:mx-a+1;
            y=(mx-b)==0?0:mx-b+1;
            z=(mx-c)==0?0:mx-c+1;
            System.out.println(x+" "+y+" "+z);
            continue;
        }
    }
	}
}

Feel free to Share your approach.
Suggestions are welcomed as always had been.