Question
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:
#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 (1Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started