Calorie Intake
Source: codechef
Difficulty: 247

Calorie Intake
Chef has decided that he will cut down on his calorie intake. He will eat atmost$X$calories in a day.
Today, he already ate$Y$sweets, each having$Z$calories. Find out how many more calories he can eat. If he has already exceeded his limit, output$-1$.
Input Format
The first and only line of input contains$3$integers -$X, Y$and$Z$.
Output Format
For each test case, output on a new line$-1$if Chef has exceeded his calorie limit
The amount of calories Chef can still eat if he has not exceeded it
Constraints$1 \le X, Y, Z \le 100$Sample 1:
Explanation:
Chef was allowed to eat$8$calories. He already ate$2 \cdot 4 = 8$. Therefore, he has$10 - 8 = 2$calories more till he hits his limit.
Sample 2:
Input
Output
10 2 6
-1
Explanation:
Chef was allowed to eat$8$calories, but he already ate$2 \cdot 6 = 12$. Therefore, he has exceeded his limit already, and we print$-1$.
Sample 3:
Input
Output
100 10 10
0

Sample Input:
10 2 4

Sample Output:
2

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

int main() {
    // your code goes here
int x,y,z;
cin>>x>>y>>z;
if(x<y*z){
    cout<<-1;
}
else{
    cout<<x-(y*z);
}
    
}

Go solution:
package main
import "fmt"

func main(){
    // your code goes here
    var x,y,z int
//  x:max calories; y:sweeats ate; z:caloriesper sweet
    fmt.Scan(&x,&y,&z)
    a:=y*z
    if x>a{
        fmt.Println(x-a)
    }else{
        fmt.Println("-1")
    }
}

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

class Codechef
{
    public static void main (String[] args) throws java.lang.Exception
    {
        Scanner sc = new Scanner(System.in);
        
       int A = sc.nextInt();
       int B = sc.nextInt();
       int C = sc.nextInt();
       
       if(A>(B*C)){
           System.out.println(A-(B*C));
       }else{
           System.out.println(-1);
       }
       
      

       
       
      
           
        // your code goes here

    }
}

JavaScript solution:
// your code goes here
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(input){
    let num=input.trim().split(" ");
    let x=parseInt(num[0]);
    let y=parseInt(num[1]);
    let z=parseInt(num[2]);
    r=y*z;
    if(r<=x){
        result=x-r;
        console.log(result)
    }
    else{
        console.log("-1")
    }
})

Python solution:
X,Y,Z = map(int, input().split())
cal = Y*Z
if cal>X:
    print(-1)
else:
    print(X-cal)

Ruby solution:
# Read the three space-separated integers from input
x, y, z = gets.split.map(&:to_i)

# Calculate total calories consumed from sweets
total = y * z

# Determine if Chef has exceeded his limit
if total > x
  puts -1
else
  puts x - total
end