CF383A.Milking cows

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Iahub helps his grandfather at the farm. Today he must milk the cows. There are n cows sitting in a row, numbered from 1 to n from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity of milk that they can give. A cow facing left sees all the cows with lower indices than her index, and a cow facing right sees all the cows with higher indices than her index. A cow that got scared once can get scared again (and lose one more unit of milk). A cow that has been milked once cannot get scared and lose any more milk. You can assume that a cow never loses all the milk she can give (a cow gives an infinitely amount of milk).

Iahub can decide the order in which he milks the cows. But he must milk each cow exactly once. Iahub wants to lose as little milk as possible. Print the minimum amount of milk that is lost.

伊阿胡布帮助他的祖父在农场工作。今天,他必须给奶牛挤奶。共有 nn 头奶牛排成一列,从左到右依次编号为 11nn。每头奶牛面朝左或面朝右。当伊阿胡布给某头奶牛挤奶时,所有“看见”这头奶牛的奶牛都会受惊,并各自减少一单位可提供的牛奶量。面朝左的奶牛能看到所有编号比它小的奶牛(即位于其左侧的所有奶牛),而面朝右的奶牛能看到所有编号比它大的奶牛(即位于其右侧的所有奶牛)。一头奶牛即使已经受惊过一次,仍可能再次受惊(并再减少一单位牛奶量)。但一头已被挤过奶的奶牛将不再受惊,也不会再损失任何牛奶量。你可以假设奶牛永远不会损失完其全部可提供的牛奶量(即每头奶牛可提供的牛奶量是无限的)。

伊阿胡布可以自行决定给奶牛挤奶的顺序,但必须恰好给每头奶牛挤一次奶。伊阿胡布希望使损失的牛奶总量尽可能少。请输出最少损失的牛奶量。

输入格式

The first line contains an integer n (1 ≤ n ≤ 200000). The second line contains n integers _a_1, _a_2, ..., a__n, where a__i is 0 if the cow number i is facing left, and 1 if it is facing right.

第一行包含一个整数 nn1n2000001 \leq n \leq 200000)。第二行包含 nn 个整数 a1,a2,,ana_1, a_2, \dots, a_n,其中 aia_i 为 0 表示第 ii 头奶牛面朝左,为 1 表示面朝右。

输出格式

Print a single integer, the minimum amount of lost milk.

Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

输出一个整数,表示损失的牛奶的最小量。

请注意,在 C++ 中不要使用 %lld 说明符来读取或写入 64 位整数。推荐使用 cincout 流,或 %I64d 说明符。

输入输出样例

  • 输入#1

    4
    0 0 1 0

    输出#1

    1
  • 输入#2

    5
    1 0 1 0 1

    输出#2

    3

说明/提示

In the first sample Iahub milks the cows in the following order: cow 3, cow 4, cow 2, cow 1. When he milks cow 3, cow 4 loses 1 unit of milk. After that, no more milk is lost.

在第一个样例中,Iahub 按如下顺序给奶牛挤奶:奶牛 3、奶牛 4、奶牛 2、奶牛 1。当他给奶牛 3 挤奶时,奶牛 4 损失了 1 单位牛奶。此后,不再有牛奶损失。

输入解题思路,AI测评打分。不知道怎么写?

首页