God beast Grass mud horse

Source: Internet
Author: User

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

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.