A Candidate has applied for dream jobs. He has done with all rounds and now is time for result. He picks a flower from pot and starts picking petal from flower saying he will get and he will not get. He always start with positive approach he will get.
There are N flowers in pot and each flower has different number of petals. if he picks any flower he picks up all the petals of that flower. we have to get the maximum sum of number of petals of the flowers so he finishes at positive outcome i.e. he will get. if its not possible print -1.
Example
There are 3 flowers in a pot. So N=3
The number of petals all flower respectively {3,1,3}
Picking all the flowers will end up at he will get for example
3:He will get , He will not get , He will get
1: He will not get
3:He will get , He will not get , He will get
So output will be 7 as he reaches at He will get at 7
Sample Input
N = 3(Number of flowers)
Number of petals in each flower (3,1,3). so 3 + 1 +3 =7
have written program for sample test case
int n = 3;
int i = 0;
int[] noofpetals = {3,1,3};
int sum = 0;
do{
int total = noofpetals[i];
for(int j = 1 ; j <=total;j++)
{
sum = sum + 1;
}
i++;
}
while(i < n);
Console.WriteLine(sum);
this works for sample test case but fails for other. for example
N = 2(number of flowers)
noofpetals in each flower = {2,2}
He picks all flowers and all petals
He will get he will not get
He will get he will not get
Here we will print -1 as he never reached he will get
suppose noofpetals in each flower is {2,3}
He will get he will not get
he will get he will not get he will get
output will be 5 as he rached at he will get at 5.
suppose number of flower N = 3
suppose noofpetals in each flower is {2,3,2}
he will get he will not get
he will get he will not get he will get
he will not get he will get
here it will be 7 as he reached he will get at 7
suppose number of flower N = 4
suppose noofpetals in each flower is {2,3,2,3}
he will get he will not get
he will get he will not get he will get
he will not get he will get
he will not get he will get he will not get
here it will be -1 as he never reached he will get
how can this be done

Faisal KhanPosted Feb 25, 2026, 5:48 AM
Just like using the Magis App, the final result depends on the last step.
He starts with “He will get”, and every petal flips the result.
Odd total petals ? He will get
Even total petals ? He will not get
Logic:
Calculate the total sum of petals.
If the sum is odd, print the sum.
If the sum is even, remove the smallest flower with an odd number of petals.
If no odd flower exists, print -1.
?? Simply make sure the final total number of petals is odd to end on a positive result.
Laim LeonPosted Feb 25, 2026, 4:35 AM
You can connect this post with tipos de flores in a simple way. The forum question talks about writing a program related to flowers and their petals. This can be linked to tipos de flores because different types of flowers have different numbers of petals and characteristics.
So instead of just calculating petals, the program could also include different flower types like roses, tulips, or daisies and process their data. In this way, programming logic and tipos de flores can be connected naturally. Visit here https://tiposdefloress.com/
Amit MohantyPosted May 29, 2023, 5:45 AM
Check this:
Mohamed Azarudeen ZPosted May 28, 2023, 11:39 AM
Initialize an array
dpof sizeNwith all elements set to-1. This array will store the maximum sum of petals for each flower.Set
dp[0]to the number of petals in the first flower. This represents the starting point of the positive outcome.Iterate through the remaining flowers (from index 1 to
N-1):For each flower, check if there exists a previous flower (from index 0 to
i-1) that has a positive outcome ("He will get").If such a flower exists, update
dp[i]with the sum of petals from the current flower and the maximum sum of petals from the previous flower.Otherwise, set
dp[i]to-1, indicating that there is no way to reach a positive outcome.The maximum sum of petals that leads to a positive outcome will be the maximum value in the
dparray.