nyoj-709-irregular egg (water problem)

Source: Internet
Author: User

Irregular Eggtime limit: ms | Memory limit:65535 KBDifficulty:2
Describe

We explore the universe to understand the wonders of the starry sky, but we are seldom aware of the dangers of hiding in the depths of the universe, staring at our earth all the while. If aliens visit us, the results may not be the same as when Columbus was on the American continent, which is history and reality.

The dormant irregular eggs found on the planet ZDM-777, whose appearance is different from the common eggs, are covered with a layer of graphite. When the person approached, the layer of graphite began to melt, can see the inside of the alien eggs are moving, irregular eggs are living things, with some heat or pressure sensor these basic central nervous system, by perceiving the heat around, select the maximum parasitic heat. However, if the surrounding area is not suitable for the parasite, irregular eggs will choose to sleep.

The surrounding heat can be expressed by a string of integers a1,a2,......, An, the irregular eggs have a certain length of L, the irregular eggs are always selected ai+ai+1+...+ai+l-1 to reach the maximum value of parasitic. If the surrounding heat is less than 0, the irregular eggs are selected for hibernation.

How does an irregular egg perceive its parasitic place? We explore the universe to understand the wonders of the starry sky, but we are seldom aware of the dangers of hiding in the depths of the universe, staring at our earth all the while. If aliens visit us, the results may not be the same as when Columbus was on the American continent, which is history and reality.

The dormant irregular eggs found on the planet ZDM-777, whose appearance is different from the common eggs, are covered with a layer of graphite. When the person approached, the layer of graphite began to melt, can see the inside of the alien eggs are moving, irregular eggs are living things, with some heat or pressure sensor these basic central nervous system, by perceiving the heat around, select the maximum parasitic heat. However, if the surrounding area is not suitable for the parasite, irregular eggs will choose to sleep.

The surrounding heat can be expressed by a string of integers a1,a2,......, An, the irregular eggs have a certain length of L, the irregular eggs are always selected ai+ai+1+...+ai+l-1 to reach the maximum value of parasitic. If the surrounding heat is less than 0, the irregular eggs are selected for hibernation.

How does an irregular egg perceive its parasitic place?

Input
First line: K indicates how many sets of test data are available.
Next, there are 2 rows for each set of test data, line 1th: L N
Line 2nd: A1 A2 ... an

"Constraint conditions"
2≤k≤5 L≤n, 1≤l≤10 1≤n≤1000-100≤ai≤100
There is a space between the data.

Output
for each set of test data, the output line: The starting position of the parasitic eggs can be. If there are multiple parasitic, select a small starting position. If there is nowhere to parasitic, then output 0.
Sample input
530  0 100-30 1003 5-100 80-80-100  80
Sample output
30

Problem Solving Ideas:

is a long array of n-l to find the maximum value.

The array is created from the given L data, and the array value is the number of the first L data.

Code

#include <stdio.h>int wen[1100];int max[1100];int main () {int k;int l,n;int i,j;int answer,maxnum;scanf ("%d", &k), while (k--) {scanf ("%d%d", &l,&n), for (i=1;i<=n;i++)    scanf ("%d", &wen[i]); for (i=1;i<= n;i++) {if (i<l)    max[i]=0;else if (i==l) {max[i]=0;for (j=i;j>=0;j--)    max[i]+=wen[j];} else    max[i]=max[i-1]+wen[i]-wen[i-l];} Maxnum=0;answer=0;for (i=l;i<=n;i++)    if (Maxnum<max[i])    {    maxnum=max[i];    answer=i-l+1;//starting from answer, so add 1    }if (maxnum==0)    printf ("0\n"), Else    printf ("%d\n", answer);} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

nyoj-709-irregular egg (water problem)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.