Itz Simple
Source: codechef
Difficulty: 791

Itz Simple
Ved and Varun are both members of Shaastra’s CnL team this year. While they are equally skilled in programming, they differ in height. Ved’s height is$K$, and Varun’s height is$P$.
Both want to watch a movie in OAT from outside the gate, without entering. There are$N$chairs available outside OAT, each with a height represented as$A_i$. These chairs can be stacked on top of each other to create a platform, allowing them to stand on it for a better view of the movie.
Tej, the OAT security officer, gives all the chairs to Varun, except for one - the tallest chair, which is given to Ved.
Now, Tej wants to know who will have a better view of the movie. If Ved has a better view, print$\text{Ved}$. If Varun has a better view, print$\text{Varun}$. If both have the same view, print$\text{Equal}$.
Note
: A person is said to have a better view if they can get a better combined height by stacking their chairs and standing on top of them.
Input Format
The first line of input will contain a single integer$T$, denoting the number of test cases.
Each test case consists of multiple lines of input.
The first line of each test case contains three space-separated integers$N$,$K$and$P$- the number of chairs, Ved's height and Varun's height
The next line contains$N$space-separated integers -$A_1, A_2, ..., A_N$.
Output Format
For each test case, output$\text{Ved}$if Ved will have a better view,$\text{Varun}$if Varun will have a better view, or$\text{Equal}$if both will have the same view.
Each character of the strings can be printed in upper or lower case.$\text{VED}$,$\text{ved}$and$\text{vEd}$will all be accepted.
Constraints$1 \le T \le 100$$1 \le N \le 100$$1 \le K, P \le 10^4$$1 \le A_i \le 100$Sample 1:
Explanation:
Test Case 1
: Varun gets all chairs except the maximum one, so he gets chair with height$1$. Ved gets chair of height$3$.
The combined height of Ved becomes$4 + 3 = 7$, and Varun's is$2 + 1 = 3$.
Test Case 3
: Ved's combined height becomes$10 + 7 = 17$, while Varun's is$6 + 1 + 2 + 5 = 14$.

Sample Input:
4
2 4 2
1 3
6 10 6
6 1 4 5 7 8
4 10 6
1 2 7 5
3 2 4
1 1 4

Sample Output:
Ved
Varun
Ved
Equal

C++ solution:
#include <bits/stdc++.h>
#include <climits>
using namespace std;

int main() {
    // your code goes here
    int t;
    cin>>t;
    while(t--){
        int n,k,p;
        cin>>n>>k>>p;
        
        int arr[n];
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        int max=INT_MIN;
        int a=0;
        for(int i=0;i<n;i++){
            if(arr[i]>max){
                max=arr[i];
               //a=a+arr[i]-max;
            }
            a=a+arr[i];
            
        }
        int v=a-max;
         
        if(k+max>v+p){
            cout<<"ved"<<endl;
        }
        else if(k+max<v+p){
            cout<<"varun"<<endl;
        }
        else{
            cout<<"equal"<<endl;
        }
    }

}

Go solution:
package main

import (
    "fmt"
    "sort"
)

func main() {
    var t int
    fmt.Scan(&t)
    for i := 0; i < t; i++ {
        var n, k, p int
        fmt.Scan(&n, &k, &p)
        chairs := make([]int, n)
        for j := 0; j < n; j++ {
            fmt.Scan(&chairs[j])
        }


        sort.Ints(chairs)
        vedHeight := k + chairs[n-1]
        varunHeight := p
        for j := 0; j < n-1; j++ {
            varunHeight += chairs[j]
        }
        if vedHeight > varunHeight {
            fmt.Println("Ved")
        } else if vedHeight < varunHeight {
            fmt.Println("Varun")
        } else {
            fmt.Println("Equal")
        }
    }
}

Java solution:
import java.util.*;
import java.lang.*;
import java.io.*;

class Codechef
{
    public static void main (String[] args) throws java.lang.Exception
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        int t = Integer.parseInt(br.readLine());
        while(t-- > 0){
            
            String[] s = br.readLine().trim().split("\\s+");
            int n = Integer.parseInt(s[0]);
            int k = Integer.parseInt(s[1]);
            int p = Integer.parseInt(s[2]);
            s = br.readLine().trim().split("\\s+");
    
            int max = 0;
            int sum=0;
            for(int i=0;i<n;i++){
                int h = Integer.parseInt(s[i]);
                max = Math.max(max , h);
                sum+=h;
            }
            sum-=max;
            if(k+max > sum+p)
                out.println("Ved");
            else if(k+max == sum+p)
                out.println("Equal");
            else
                out.println("Varun");
        }
        out.flush();
        out.close();
    }
}

JavaScript solution:
// your code goes here
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function(input) {
 let data =input.trim().split('\n');
 let T = parseInt(data[0]);
 
 let result = [];
 let index = 1;
 
 for(let t=0; t<T; t++){
     let [N,K,P]= data[index].split(' ').map(Number)
     index++;
     
     let A = data[index].split(' ').map(Number);
     index++;
     
     let maxchair = Math.max(...A);
     A.splice(A.indexOf(maxchair),1);
     
     let vedHeight = K+ maxchair;
     let varunHeight = P+A.reduce((sum, height) => sum+height,0);
     
     
     if (vedHeight > varunHeight ){
         result.push('Ved');
         
     }else if(vedHeight<varunHeight){
         result.push('Varun');
         
     }else{
         result.push("Equal")
     }
 }
 
 console.log(result.join('\n'))
})

Python solution:
# cook your dish here
T = int(input())

for _ in range(T):
    N, K, P = map(int, input().split())
    A = list(map(int, input().split()))
    
    A.sort()
    tallest = A[-1]
    ved_height = K + tallest
    varun_height = P + sum(A[:-1])  # all chairs except the tallest
    
    if ved_height > varun_height:
        print("Ved")
    elif ved_height < varun_height:
        print("Varun")
    else:
        print("Equal")

Ruby solution:
def solve
  test_cases = gets.to_i
  test_cases.times do
    n, k, p = gets.split.map(&:to_i)
    a = gets.split.map(&:to_i)
    
    if a.empty?
      puts "Equal"
      next
    end

    a_sorted = a.sort
    tallest = a_sorted.last
    varun_chairs = a_sorted[0...-1]

    ved_height = k + tallest
    varun_height = p + varun_chairs.sum

    if ved_height > varun_height
      puts "Ved"
    elsif ved_height < varun_height
      puts "Varun"
    else
      puts "Equal"
    end
  end
end

solve