Too Many Oranges
Source: codechef
Difficulty: 735

Too Many Oranges
Chef has$N$oranges with him. Each orange has either$10, 11,$or$12$slices.
Chef wanted to eat
exactly$K$slices of orange. However, the oranges were too tasty, and Chef ended up eating all$N$of them!
Chef wasn't paying attention, so he didn't count the number of slices he ate, and he also doesn't know how many slices each orange had - the only thing he knows is that each orange has either$10, 11,$or$12$slices.
Is it possible that Chef ate exactly$K$slices from$N$oranges?
Input Format
The first line of input will contain a single integer$T$, denoting the number of test cases.
Each test case consists of a single line of input, containing two space-separated integers$N$and$K$— the number of oranges, and the number of slices Chef wants to eat.
Output Format
For each test case, output on a new line the answer:
"YES"
if Chef could have eaten exactly$N$orange slices, and
"NO"
otherwise. The output should be without quotes.
Each character of the output may be printed in either uppercase or lowercase, i.e, the strings
No
,
NO
,
nO
, and
no
will all be treated as equivalent.
Constraints$1 \leq T \leq 5000$$1 \leq N \leq 30$$1 \leq K \leq 500$Sample 1:
Explanation:
Test case$1$:
Chef ate only one orange. It's possible it had$10$slices, so the answer is
"YES"
.
Test case$2$:
Chef ate only one orange. It must've had either$10, 11,$or$12$slices, so there's no chance that Chef ate exactly$9$slices.
Test case$3$:
Chef ate two oranges. It's possible that one of them had$10$slices and the other had$11$slices, for a total of$10+11=21$.
Test case$4$:
Chef ate four oranges. If all four had$12$slices, Chef would've eaten$48$slices.
Test case$5$:
Chef ate five oranges. It can be shown that there's no way for Chef to have eaten five oranges and yet have eaten exactly$49$slices.

Sample Input:
5
1 10
1 9
2 21
4 48
5 49

Sample Output:
YES
NO
YES
YES
NO

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

int main() {
    int t;
    cin >> t;
    while(t--)
    {
        int n, k;
        cin >> n >> k;
        if(k >= n * 10 && k <= n*12)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    
    return 0;
}

Go solution:
package main

import (
    "bufio"
    "fmt"
    "os"
    "strconv"
    "strings"
)

func canEatExactlyKSlices(N, K int) string {
    minSlices := 10 * N
    maxSlices := 12 * N
    if minSlices <= K && K <= maxSlices {
        return "YES"
    }
    return "NO"
}

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Scan()
    T, _ := strconv.Atoi(scanner.Text())

    results := make([]string, T)

    for i := 0; i < T; i++ {
        scanner.Scan()
        input := strings.Split(scanner.Text(), " ")
        N, _ := strconv.Atoi(input[0])
        K, _ := strconv.Atoi(input[1])
        results[i] = canEatExactlyKSlices(N, K)
    }

    fmt.Println(strings.Join(results, "\n"))
}

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

class Codechef
{
    public static void main (String[] args) 
    {
        // your code goes here
     Scanner sc = new Scanner(System.in);
        int T = sc.nextInt(); // Number of test cases
        
        StringBuilder output = new StringBuilder();
        
        while (T-- > 0) {
            int N = sc.nextInt(); 
            int K = sc.nextInt(); 


            int minSlices = N * 10; 
            int maxSlices = N * 12; 


            if (K >= minSlices && K <= maxSlices) {
                output.append("YES\n");
            } else {
                output.append("NO\n");
            }
        }
        
        System.out.print(output.toString());
        sc.close();
    }
}

JavaScript solution:
// your code goes here
let input = '';
process.stdin.on('data', function (chunk) {
    input += chunk;
});

process.stdin.on('end', function () {
    const lines = input.trim().split('\n');
    const T = parseInt(lines[0], 10); // number of test cases
    
    let results = [];
    
    for (let i = 1; i <= T; i++) {
        const [N, K] = lines[i].split(' ').map(Number);
        
        const minSlices = 10 * N;
        const maxSlices = 12 * N;

        // Check if K is within the possible range
        if (minSlices <= K && K <= maxSlices) {
            results.push("YES");
        } else {
            results.push("NO");
        }
    }
    
    console.log(results.join('\n'));
});

Python solution:
# cook your dish here
def can_achieve_exact_slices(num_oranges, target_slices):
    min_possible_slices = num_oranges * 10
    max_possible_slices = num_oranges * 12
    return min_possible_slices <= target_slices <= max_possible_slices

test_cases = int(input())
results = []
for _ in range(test_cases):
    num_oranges, target_slices = map(int, input().split())
    if can_achieve_exact_slices(num_oranges, target_slices):
        results.append("YES")
    else:
        results.append("NO")

print("\n".join(results))

Ruby solution:
def main
  test_cases = gets.to_i
  results = []
  
  test_cases.times do
    line = gets
    next unless line  # Skip if no input
    
    n, k = line.split.map(&:to_i)
    
    min_slices = n * 10
    max_slices = n * 12
    
    if k >= min_slices && k <= max_slices
      results << "YES"
    else
      results << "NO"
    end
  end
  
  puts results.join("\n")
end

main