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.
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;}