Data Structure Happiness

Source: Internet
Author: User

Problem description

This day is smallVBirthday, he received a gift from his friends.
Now, LittleVYesNPiece of gift, he would have thisNThe gift is lined up in a row, numbered1n a satisfactory value w[i] Now small v [l, R]happiness large.
[l, R] ([l, R]* ([l, R] All gift satisfaction values in the and)
small v want to know what he can get happiness Span class= "FONTSTYLE0" > What is the maximum, can you help him?


★ data input
first behavior a positive integer n Second behavior n integers w[1], w[2], ..., W[n]
Span class= "Fontstyle0", Where:
for 50%1<=n<=100, 0<=w[i]<=100
for 80%1<=n<=1,000, 0<=w[i] <=1,000
100%1<=n<=100,000, 0<=w[i]<=10,000


★ data output
The maximum happiness value that small V can obtain.


★

Input

3

1 2 3

Output

10

Input

3

2 1 3

Output

9

Thinking of solving problems

Violence

Each number is a starting point, expanding to either side, extending to a number smaller than it or the array boundary to stop. Expansion process Statistics sum

The number that is the starting point is the minimum value of this number.

Update the final answer with (sum* as the number of starting points) max_happiness

Code

1#include <stdio.h>2#include <stdlib.h>3 4 intMain ()5 {6     inti,j,k;7     intN;8scanf"%d",&n);9     int*p = (int*)malloc(sizeof(int)*n);Ten      for(i=0; i<n;i++) Onescanf"%d", p+i); A     //------------------------------------- -__int64 maxhap=0; -      the      for(i=0; i<n;i++) -     { -__int64 sum=0; -          for(j=i-1; j>=0&&p[j]>=p[i];j--) +sum+=P[j]; -          for(k=i;k<n&&p[k]>=p[i];k++) +sum+=P[k]; AMaxhap = Sum*p[i]>maxhap? sum*P[i]: Maxhap; at     } -printf"%i64d", Maxhap); -     //------------------------------------- -      Free(p); -     return 0; -}

Data Structure Happiness

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.