c语言sscanf函数的用法是什么
283
2022-08-27
Codeforces Round #344 (Div. 2) E. Product Sum (三分)
E. Product Sum
time limit per test
memory limit per test
input
output
Blake is the boss of Kris, however, this doesn't spoil their friendship. They often gather at the bar to talk about intriguing problems about maximising some values. This time the problem is really special.
You are given an array a of length n. The characteristic of this array is the value
— the sum of the products of the valuesai by i. One may perform the following operation exactly once: pick some element of the array and move to any position. In particular, it's allowed to move the element to the beginning or to the end of the array. Also, it's allowed to put it back to the initial position. The goal is to get the array with the maximum possible value of characteristic.
Input
The first line of the input contains a single integer n (2 ≤ n ≤ 200 000) — the size of the array a.
The second line contains n integers ai (1 ≤ i ≤ n, |ai| ≤ 1 000 000) — the elements of the array a.
Output
Print a single integer — the maximum possible value of characteristic of a
Examples
input
44 3 2 5
output
39
input
51 1 2 7 1
output
49
input
31 1 2
output
9
Note
In the first sample, one may pick the first element and place it before the third (before 5). Thus, the answer will be3·1 + 2·2 + 4·3 + 5·4 = 39.
In the second sample, one may pick the fifth element of the array and place it before the third. The answer will be1·1 + 1·2 + 1·3 + 2·4 + 7·5 = 49.
题解:给你出n个数,计算sum(i*a[i]) 。然后你可以任意挪动一个数的位置,且只能移动一个数。让你求移动后的最大值sum(i*a[i])。三分。枚举每个数,然后三分移动到各个位置寻求最大值。具体看代码吧。
AC代码:
#pragma comment(linker, "/STACK:102400000,102400000")//#include
发表评论
暂时没有评论,来抢沙发吧~