Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Kattis - Planting Trees - C Language My code is able to pass the test cases shown, but not hidden test cases . Need an

Kattis - Planting Trees - C Language

My code is able to pass the test cases shown, but not hidden test cases. Need an expert's help to examine what is wrong with my code below:

image text in transcribed

#include

int main(void) {

int i, days, min, max, count, tree[100000];

scanf("%d", &days);

for(i = 0; i

scanf("%d", &tree[i]);

min = tree[0];

max = tree[0], count = 1;

for(i = 1; i

if(tree[i]

min = tree[i]; // last day.

if(tree[i] > max) {

max = tree[i];

count = 1;

}

if(tree[i] == max) // latest first day if repeat max

count++;

}

if(max + count

printf("%d ", min + days + 1);

else

printf("%d ", max + count + 1);

return 0;

}

Planting Trees Farmer Jon has recently bought n tree seedlings that he wants to plant in his yard. It takes 1 day for Jon to plant a seedling, and for each tree Jon knows exactly in how many days after planting it grows to full maturity. Jon would also like to throw a party for his farmer friends, but in order to impress them he would like to organize the party only after all the trees have grown. More precisely, the party can be organized at earliest on the next day after the last tree has grown up Help Jon to find out when is the earliest day when the party can take place. Jon can choose the order of planting the trees as he likes, so he wants to plant the trees in such a way that the party will be as soon as possible Photo from Wikipedia, after U. S. Department of Agriculture Input The input consists of two lines. The first line contains a single integer N (1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Contemporary Issues In Database Design And Information Systems Development

Authors: Keng Siau

1st Edition

1599042894, 978-1599042893

More Books

Students also viewed these Databases questions

Question

1. Identify six different types of history.

Answered: 1 week ago

Question

2. Define the grand narrative.

Answered: 1 week ago

Question

4. Describe the role of narratives in constructing history.

Answered: 1 week ago