Movie Snacks
Source: codechef
Difficulty: 263

Movie Snacks
Chef is watching a movie, and during the intermission, wants to get himself some snacks.
A bucket of popcorn costs$X$rupees, and a drink costs$Y$rupees.
There is also a combo offer available, which provides one bucket of popcorn and one drink at a cost of$Z$rupees.
Chef wants to buy two buckets of popcorn and three drinks.
What's the
minimum
amount he needs to pay to do so?
Input Format
The first and only line of input will contain three space-separated integers$X, Y,$and$Z$— the price of one bucket of popcorn, one drink, and the combo, respectively.
Output Format
Print a single integer: the minimum price Chef needs to pay to buy two buckets of popcorn and three drinks.
Constraints$50 \leq X, Y, Z \leq 200$$X, Y \le Z$Sample 1:
Explanation:
We can use$2$combo offers for$160$each and then a drink for$70$, totalling$390$.
Sample 2:
Input
Output
110 80 200
460
Explanation:
It is optimal to buy all the$2$popcorns and$3$drinks individually for$2 \cdot 110 + 3 \cdot 80 = 460$.

Sample Input:
100 70 160

Sample Output:
390

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

int main() {
    int X,Y,Z;
    cin >> X >> Y >> Z;
    if(X+Y>Z) {
      cout << 2*(Z)+Y; 
    }
    else {
        cout << 2*(X+Y)+Y;
    }// your code goes here

}

Go solution:
package main
import "fmt"

func main(){
    // your code goes here
    var x,y,z int
    fmt.Scan(&x,&y,&z)
    if z<x+y{
    
        amt:=(2*z)+y
        fmt.Println(amt)
    }else{
        amt:=(2*x)+(3*y)
        fmt.Println(amt)
        
    }
        
    
}

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

class Codechef
{
    public static void main (String[] args) throws java.lang.Exception
    {
        // your code goes here
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y  = sc.nextInt();
        int z = sc.nextInt();
        int option1 = 2* x + 3 *y;
        int option2 = 2 * z + y;
        int option3 =  z + x + 2 * y;
        int minCost =Math.min(option1, Math.min(option2, option3));
        System.out.println(minCost);
        sc.close();
        

    }
}

JavaScript solution:
// your code goes here
const ip = require('fs').readFileSync('/dev/stdin','utf8');

const data = ip.split('\n');

let index=0;


    const[x,y,z] = data[index++].split(' ').map(Number);
    
    console.log(Math.min((2*x + 3*y),(2*z + y)))

Python solution:
# cook your dish here
x, y, z = map(int,input().split())

if (x+y) < z:
    print((2*x) + (3*y))
else:
    print((2*z)+y)

Ruby solution:
# Read the input values
input = gets.chomp
x, y, z = input.split.map(&:to_i)

# Calculate the minimum cost
if x + y < z
  # Buying individually is cheaper
  puts 2 * x + 3 * y
else
  # Buying combos is cheaper
  puts 2 * z + y
end