# QLK00 - Editorial

Practice

Contest

Author: Sibasish Ghosh

Tester: Saytabrat Panda

Editorialist: Sibasish Ghosh

CAKEWALK

None

# PROBLEM:

You are given a string of length N consisting of 0's,1's and 2's, which represents the witcher’s past contracts (0\rightarrow No help; 1\rightarrow Yennefer; 2\rightarrow Triss). For the next contract, the witcher will choose a mage who has helped him in at least N/2 previous contracts (if both mages satisfy the condition, then he will choose Yennefer). If none satisfies the condition, he will take up the contract alone. You have to tell who will the witcher choose to help him with the next contract.

# QUICK EXPLANATION:

I don’t think it’s possible to explain any shorter than the explanation below. So straight away head to the following section.

# EXPLANATION:

Count the number of 1's and 2's. Let them be x and y respectively. If x \geq N/2, print Yennefer of Vengerberg. Else if, y \geq N/2, print Triss Merigold. If none of the above conditions are true, print Lone Wolf.

# SOLUTIONS:

Setter's/Editorialist's Solution
#include<bits/stdc++.h>
#define mod 1000000007
#define F first
#define S second
#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()

using namespace std;
typedef long long int ll;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("input2.txt","r",stdin);
// freopen("output2.txt","w",stdout);
ll t=1;
cin>>t;
while(t--)
{
ll n,i,c1=0,c2=0;
cin>>n;
string s,ans="Lone Wolf";
cin>>s;
for(auto &ch:s)
{
if(ch == '1')
c1++;
if(ch == '2')
c2++;
}
if(c2 >= n/2)
ans="Triss Merigold";
if(c1 >= n/2)
ans="Yennefer of Vengerberg";
cout<<ans<<"\n";
}
return 0;
}

Tester's Solution

import java.util.*;import java.io.*;import java.math.*;

public class Main
{

public static void process()throws IOException
{
int n=ni();
char arr[]=nln().toCharArray();
int y=0,t=0;

for(char i : arr){
if(i=='1')
y++;
else if(i=='2')
t++;
}

if(y>=n/2)
pn("Yennefer of Vengerberg ");
else if(t>=n/2)
pn("Triss Merigold");
else
pn("Lone Wolf");
}

static PrintWriter out;
public static void main(String[]args)throws IOException
{
out = new PrintWriter(System.out);
boolean oj = true;

//oj = System.getProperty("ONLINE_JUDGE") != null;

long s = System.currentTimeMillis();
int t=1;
t=ni();
while(t-->0)
process();
out.flush();
if(!oj)
System.out.println(System.currentTimeMillis()-s+"ms");
System.out.close();
}

static void pn(Object o){out.println(o);}
static int ni()throws IOException{return sc.nextInt();}
static String nln()throws IOException{return sc.nextLine();}

/////////////////////////////////////////////////////////////////////////////////////////////////////////

String next()throws IOException{
while (st == null || !st.hasMoreElements()) {try{
catch (IOException  e){ e.printStackTrace(); }}
return st.nextToken(); } int nextInt() throws IOException{
return Integer.parseInt(next());}
long nextLong() throws IOException
{return Long.parseLong(next());}
double nextDouble()throws IOException { return Double.parseDouble(next()); }
String nextLine() throws IOException{ String str = ""; try{
str = br.readLine();} catch (IOException e){
e.printStackTrace();} return str;}}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}