https://atcoder.jp/contests/arc063/tasks/arc063_b
There are NN towns located in a line, conveniently numbered 11 through NN. Takahashi the merchant is
going on a travel from town 11 to town NN, buying and selling apples.
Takahashi will begin the travel at town 11, with no apple in his possession.
The actions that can be performed during the travel are as follows:
Move: When at town ii (i<Ni<N), move to town i+1i+1.Merchandise: Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that oneapple can always be bought and sold for AiAi yen (the currency of Japan) at town ii (1≦i≦N1≦i≦N), where AiAi are distinct integers. Also, you can assume that he has an infinite supply of money.For some reason, there is a constraint on merchandising apple during the travel:
the sum of the number of apples bought and the number of apples sold during
the whole travel, must be at most TT. (Note that a single
apple can be counted in both.)
During the travel, Takahashi will perform actions so that the profit of the travel is maximized.
Here, the profit of the travel is the amount of money that is gained by selling apples, minus
the amount of money that is spent on buying apples. Note that we are not interested in
apples in his possession at the end of the travel.
Aoki, a business rival of Takahashi, wants to trouble Takahashi by manipulating the
market price of apples. Prior to the beginning of Takahashi's travel, Aoki can change
AiAi into another arbitrary non-negative integer A′iAi′ for any town ii, any number of
times. The cost of performing this operation is |Ai−A′i||Ai−Ai′|. After performing this
operation, different towns may have equal values of AiAi.
Aoki's objective is to decrease Takahashi's expected profit by at least 11 yen.
Find the minimum total cost to achieve it. You may assume that Takahashi's
expected profit is initially at least 11 yen.
The input is given from Standard Input in the following format:
NN TT A1A1 A2A2 ...... ANANPrint the minimum total cost to decrease Takahashi's expected profit by at least 11 yen.
Copy
3 2 100 50 200Copy
1In the initial state, Takahashi can achieve the maximum profit of 150150 yen as follows:
Move from town 11 to town 22.Buy one apple for 5050 yen at town 22.Move from town 22 to town 33.Sell one apple for 200200 yen at town 33.If, for example, Aoki changes the price of an apple at town 22 from 5050 yen to 5151 yen,
Takahashi will not be able to achieve the profit of 150150 yen. The cost of performing this
operation is 11, thus the answer is 11.
There are other ways to decrease Takahashi's expected profit, such as changing the price
of an apple at town 33 from 200200 yen to 199199 yen.
Copy
5 8 50 30 40 10 20Copy
2Copy
10 100 7 10 4 5 9 3 6 8 2 1Copy
2题意看了半个小时,大概是说一个人沿着X轴正半轴方向走,不能回头,轴上有N个城市,每个城市有一个权值value,各不相同,这个人可以选择在该城市买苹果,每个花费value元,或者卖苹果,value元/个,这样最终一定会有一种或多种方案产生某个最大收益。然后有另一个人,他可以选择这N个城市中的任意城市然后调整其权值,并产生(调整后value-调整前value)的花费,问后面这个人 使前者无法达到原来最大收益 的最小花费。
前者想要获得最大收益,肯定是在前面一个花费较小的地方买苹果,然后去后面一个
花费较大的地方卖苹果。所以最大收益就是n*(n+1)/2个差值中最大的那些。想要破坏最大
收益,只要改动最大差值涉及的城市即可。特殊情况考虑如果有两个差值共用一个数,明
显也是要改两个城市,且任何情况下改动后不会一定出现更大的差值。
The end;