Descriptive narrative
Love found some treasure. And these treasures are endless!. When he was ready to rush up to rob the treasure. Came out a mere patron of the beast. Called the Grass mud Horse!
The Sacred beast guarding the treasure said: "There are heap of n treasures." They are endless, you take away, there will be so many of the original treasure, but you can only take a continuous x heap of treasure. And you can't repeatedly take a continuous x heap of treasures. Assuming you do this, all the treasures will disappear. Reading is very clever. He was able to take away the most treasures, so he shouted, "My!" It's mine! It's All mine!
”。 Rushed up to ransacked. Now tell you the number of treasures in each heap, do you know how many treasures you have received this time? Hint: If there are three piles of treasure, the number of treasures in each heap is 1 2 1, then the first thing to do is to take a bunch: 1 + 2 + 1 = 4 and then go for two consecutive piles: (1 + 2) + (2 + 1) = 6 finally take three consecutive piles: (1 + 2 + 1) = 4 The Treasure is 14
Input
Starts with an integer t that represents the T-group test data
Then each group starts with an n, which means there's n heap of treasures
The next line has n numbers, representing the number of treasures per heap
n<50000 number of treasures per heap <10000
Output
Output the number of treasures taken away
Example input
1
3
1 2 1
Example output
-
#include <iostream> #include <cstdio> #include <cstring>using namespace Std;int n;__int64 a[10010],b[ 10010],sum;int Main () { int t; scanf ("%d", &t); while (t--) { scanf ("%d", &n); sum=0; Memset (b,0,sizeof (b)); memset (A,0,sizeof (a)); for (int i=1;i<=n;i++) { scanf ("%d", &a[i]); } for (int i=1;i<=n;i++) { b[i]= (a[i]* (n-i+1)) *i; } for (int i=1;i<=n;i++) sum+=b[i]; printf ("%i64d\n", sum); } return 0;}
God beast Grass mud horse