Watermelon codechef lunchtime Problem solution with explanation| September Lunchtime-
Problem Statement-
Let's call a sequence good if the sum of all its elements is .
You have a sequence of integers . You may perform any number of operations on this sequence (including zero). In one operation, you should choose a valid index and decrease by . Can you make the sequence good using these operations?
Input
- The first line of the input contains a single integer denoting the number of test cases. The description of test cases follows.
- The first line of each test case contains a single integer .
- The second line contains space-separated integers .
Output
For each test case, print a single line containing the string "YES"
if it is possible to make the given sequence good or "NO"
if it is impossible.
Constraints
- for each valid
Subtasks
Subtask #1 (10 points):
Subtask #2 (30 points):
Subtask #3 (60 points): original constraints
Example Input
2
1
-1
2
1 2
Example Output
NO
YES
Explanation
Example case 2: We can perform two operations ― subtract from and from .
link of Problem->https://www.codechef.com/LTIME88B/problems/WATMELON
Watermelon CodeChef lunchtime Problem solution->
You may perform any number of operations on this sequence (including zero).
means you we can subtract i any number of time.
but we know that we will always have i=1 that is first index and every number is multiple of 1 so we can generate 0 by subtracting 1 any number of times so the conclusion is if the sum is grater then 0 ans is always "YES" because we can generate 0 by subtracting 1 any number of time.
here we need a little observation for this question.
complete code of the problem
Comments
Post a Comment