WC 6.2 Farm Points

Lisbeth is addicted to an online game called FarmEasy. She has to create a farm where the crops grow according to the weather of the day. If the weather improves, all the crops grow to a certain height even if the crop was planted on the same day, and if the weather worsens, parts of all the crops fall off decreasing the height. She can only plant one crop a day and harvest it anytime she wants. Each day she has the choice to plant a crop, harvest a crop she has previously planted or do nothing. She gets points on the basis of the increase in height of her crops she planted.

The height for the crop for each day is given in an array. You have to find out what is the maximum amount of points she can collect by planting and harvesting her crops.

Input Format:
T
n1
x1 x2 x3… xn1
n2
y1 y2 y3… yn1

T= number of testcases
n1= length of the first array
x1... xn1= array of heights for each day
And so on

Example:
2
3
5 10 100
Answer: 185
Lisbeth plants a crop on the first and the second day and harvest both on the third day. The first plant gives her 95 points and the second plant gives her 90 points.
3
100 50 10
Answer: 0
There is no way she would gain points in this scenario so she doesn’t do anything.
INPUT:
5
7
9 20 6 2 8 3 30
10
9856 7452 5468 5223 4896 4567 4012 3015 2896 2887
6
6523 4235 4112 3201 1984 8564
5
8 10 60 50 20
22
612 279 89 198 58 742 148 576 732 122 669 777 722 32 906 707 96 314 206 339 45 102

This challenge is worth 80 points.

You must be logged in to submit a solution

View ranklist for this challenge
About scoring and submission

Contact Us


Kunal Desai : 7715051136

Neelraj Patil : 9930671144



Privacy Policy