D - MaratonIME in the golden moment

简介: D - MaratonIME in the golden moment

Statements

It is a common knowledge the importance in practicing a physical activity, mainly when you take part in ICPC competitions. Keeping this in mind, Giovana Delfino invited her friends from MaratonIME to go rowing.

The initial total ability of the boat is 0. Despite the equal enthusiasm of all members, each friend i has a physical ability h(i). Dear teacher Gabi knows that whenever two friends x and y are together in the boat, the boat's total ability is increased by h(xh(y).

Giovana invited n friends, but rowing is not always possible when you have programming assignments and exams of the great professor Arnaldo Mandel ahead, so sometimes not everyone shows up. However, the teacher Gabi is very optimistic and hopes that, for the final semester competition, all n friends will attend in order to increase MaratonIME odds. Help Gabi find the total ability of the boat in this possible golden moment, assuming all friends show up.

Input

The first line contains one integer n (1 ≤ n ≤ 105) - the number of friends invited to row.

The second line contains n integers h1, h2, ..., hn (1 ≤ hi ≤ 3·104) - the abilities of each member.

Output

Print one integer - the boat's total ability in the golden moment.

Examples

Input

2

5 10


Output

50


Input

4

1 3 7 11


Output

152


Note

In the first example, in the golden moment there will be two members on the boat, then the ability there will be 5 × 10 = 50.

题目大意及思路:给你n个数,让你求第i个数和后面的数的乘积。

反思:直接用的暴力,超时了,最后也没想出来用什么办法。结束后,想了想,可以用一个数组,来存储后面的数的总和,最后的复杂度就低了O(n)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node
{
    int x;
    long long int s;
} st[100100];
int main()
{
    long long int sum;
    int n, i;
    sum = 0;
    scanf("%d", &n);
    scanf("%d", &st[0].x);
    st[0].s = st[0].x;
    for(i = 1; i < n; i++)
    {
        scanf("%d", &st[i].x);
        st[i].s = st[i].x + st[i-1].s;
    }
    for(i = 0; i < n; i++)
    {
        sum = sum + st[i].x * (st[n-1].s - st[i].s);
    }
    printf("%lld\n", sum);
    return 0;
}


相关文章
|
网络安全 API Python
Python下载大文件时遇到了SSL握手失败,要怎么办?
在 Python 数据集下载中常遇程序中断问题, 如网络不稳定、API请求数量限制等。网络不稳定时可通过实现重试机制与使用短效代理IP应对。示例代码利用 `requests` 库实现自动重试功能,提高下载成功率。对于 API 请求数量限制,可通过控制请求速率和轮换代理IP解决。示例展示了如何控制请求间隔及使用代理池轮换来避免触发限制。这些技巧有助于确保下载任务的顺利进行。
|
安全 编译器 Swift
探索iOS开发之旅:Swift编程语言的魅力与挑战
【9月更文挑战第5天】在iOS应用开发的广阔天地中,Swift作为苹果官方推荐的编程语言,以其简洁、高效和安全的特点,成为了开发者的新宠。本文将带领你领略Swift语言的独特魅力,同时探讨在实际开发过程中可能遇到的挑战,以及如何克服这些挑战,成为一名优秀的iOS开发者。
139 5
|
供应链 安全 物联网
未来已来:探索新兴技术的发展趋势与应用场景
【9月更文挑战第5天】本文将深入探讨新兴技术如区块链、物联网、虚拟现实等的发展趋势和应用场景。我们将通过分析这些技术的基本原理,以及它们在现实世界中的应用,来揭示它们如何改变我们的生活和工作方式。我们将看到,这些技术的发展不仅仅是技术的进步,更是我们理解和互动世界方式的改变。我们将以通俗易懂的语言,深入浅出地解析这些复杂的技术,并展示它们的实际应用。无论你是技术专家,还是对这些新技术感兴趣的普通读者,这篇文章都将为你提供有价值的信息和启示。
|
JavaScript 前端开发
JS的入口函数,并讲解入口函数的作用
JS的入口函数,并讲解入口函数的作用
98 0
|
存储 缓存 前端开发
从此告别网速慢,轻松掌握浏览器缓存知识点!(二)
从此告别网速慢,轻松掌握浏览器缓存知识点!
|
关系型数据库 MySQL 索引
Mysql锁之——行锁
Mysql锁之——行锁
|
存储 Java 编译器
JavaSE学习--数据类型和运算符
JavaSE学习--数据类型和运算符
146 0
|
知识图谱 Python
|
关系型数据库 MySQL Linux
在工作中CentOS7所有方式安装MySQL5.7(5.7最新版本)(下)
在工作中CentOS7所有方式安装MySQL5.7(5.7最新版本)
486 0
编程小技巧3-IDEA插件Power Mode || 写代码帅是一辈子的事
编程小技巧3-IDEA插件Power Mode || 写代码帅是一辈子的事
709 0
编程小技巧3-IDEA插件Power Mode || 写代码帅是一辈子的事

热门文章

最新文章