Take discount or Not

There are NN items in a shop. You know that the price of the ii-the item is AiAi. Chef wants to buy all the NN items.

There is also a discount coupon that costs XX rupees and reduces the cost of every item by YY rupees. If the price of an item was initially ≤Y≤Y, it becomes free, i.e, costs 00.

Determine whether Chef should buy the discount coupon or not. The chef will buy the discount coupon if and only if the total price he pays after buying the discount coupon is strictly less than the price he pays without buying the discount coupon.

Input Format

  • The first line of input will contain a single integer TT, denoting the number of test cases. The description of the test cases follows.
  • Each test case consists of two lines of input.
    • The first line of the test case contains three space-separated integers — NN, XX, and YY.
    • The second line contains NN space-separated integers — A1, A2,…, ANA1, A2,…, and AN.

Output Format

  • For each test case, output COUPON if Chef should buy the discount coupon, and NO COUPON otherwise.

Each letter of the output may be printed in either lowercase or uppercase. For example, the strings couponCouPoN, and COUPON will all be treated as equivalent.

Constraints

  • 1≤T≤10001≤T≤1000
  • 1≤N≤1001≤N≤100
  • 1≤X, Y≤1051≤X, Y≤105
  • 1≤Ai≤105
//This code is written by Souvik Ghosh
import java.util.*;
public class discountCoupon {
    public static void main(String[] args) {
        //copy from here for codechef
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        for (int i = 0; i < t; i++) {
            int n = sc.nextInt();
            int x = sc.nextInt();
            int y = sc.nextInt();
            int wd = 0;
            int d = 0;
            int array[] = new int[n];
            for (int k = 0; k < n; k++) {
                array[k] = sc.nextInt();
            }
            for (int j = 0; j < n; j++) {
                wd += array[j];
                if (array[j] > y) {
                    d += (array[j] - y);
                }

            }
            if ((d + x) < wd) {
                System.out.println("COUPON");
            } else {
                System.out.println("NO COUPON");
            }

        }
    }

}

Related Posts

CSS Cheatsheet

Transform your web design game with my CSS cheatsheet! Master the art of styling, dive into essential properties and selectors, and create visually stunning websites effortlessly. Whether…

HTML Cheatsheet

Unleash your web development potential with my HTML cheatsheet! Elevate your coding skills, master essential tags and attributes, and build stunning websites with ease. Whether you’re a…

Git&GitHub Cheatsheet

Elevate your Git and GitHub game with my ultimate cheatsheet! Unlock the power of version control, streamline collaboration, and boost productivity. Navigate the complexities of Git commands…

Command Line Cheatsheet

Master the Command Line effortlessly with my comprehensive cheatsheet! Streamline your workflow, boost productivity, and become a command line guru. Unlock essential commands, shortcuts, and tips to…

OpenAI’s APIs Notes

Unlock the potential of OpenAI’s APIs with my comprehensive notes! Dive into the world of cutting-edge artificial intelligence, explore the capabilities of GPT-4 and beyond, and learn…

SQL Notes

Discover the essence of SQL with my comprehensive notes! Dive into the world of Structured Query Language, unraveling the complexities, and mastering database management. Elevate your SQL…

Leave a Reply

Your email address will not be published. Required fields are marked *