CLSAVE - Editorial

PROBLEM LINK:

Practice
Contest

Author: Subham Das
Tester: Soumik Sarkar
Editorialist: Soumik Sarkar

DIFFICULTY:

CAKEWALK

PREREQUISITES:

Loops

PROBLEM:

Find the sum of N numbers and check whether the sum is less than or equal to half of another number S.

EXPLANATION:

An array of N values is provided along with a value S. The total expenditure is the sum of the N values provided. The sum can be obtained using a loop over the N input values.

sum = 0
for each val of the N values
    sum = sum + val

Now Chef’s savings are atleast half of S when the total expenditure is less than or equal to half of S.

if sum ≤ S/2
    print "Yes"
else
    print "No"

Complexity of this approach is \mathcal{O}(N).

TESTER’S SOLUTION:

Tester’s solution can be found here.