There are N towns located in a line, conveniently numbered 1 through N. Takahashi the merchant is going on a travel from town 1 to town N, buying and selling apples.
Takahashi will begin the travel at town 1, with no apple in his possession. The actions that can be performed during the travel are as follows:
Move: When at town i (i<N), move to town i+1.
Merchandise: Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for Ai yen (the currency of Japan) at town i (1≤i≤N), where Ai 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 T. (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 Ai into another arbitrary non-negative integer Ai‘ for any town i, any number of times. The cost of performing this operation is |Ai?Ai‘|. After performing this operation, different towns may have equal values of Ai.
Aoki‘s objective is to decrease Takahashi‘s expected profit by at least 1 yen. Find the minimum total cost to achieve it. You may assume that Takahashi‘s expected profit is initially at least 1 yen.
Constraints
1≤N≤105
1≤Ai≤109 (1≤i≤N)
Ai are distinct.
2≤T≤109
In the initial state, Takahashi‘s expected profit is at least 1 yen.
Print the minimum total cost to decrease Takahashi‘s expected profit by at least 1 yen.
In the initial state, Takahashi can achieve the maximum profit of 150 yen as follows:
1.Move from town 1 to town 2.
2.Buy one apple for 50 yen at town 2.
3.Move from town 2 to town 3.
4.Sell one apple for 200 yen at town 3.
If, for example, Aoki changes the price of an apple at town 2 from 50 yen to 51 yen, Takahashi will not be able to achieve the profit of 150 yen. The cost of performing this operation is 1, thus the answer is 1.
There are other ways to decrease Takahashi‘s expected profit, such as changing the price of an apple at town 3 from 200 yen to 199 yen.
em题目的意思就是说一个商人可以从一个地方买苹果,然后再下不知道几个地方卖出去,每个地方都有个苹果的价值(且不相等),他想取得最大的利润,(毕竟商人)。而另一个竞争对手想要阻止他,哪怕只令他少赚一块钱,他可以任意修改地方苹果售价,但是要付出相等的代价。求最小的代价。
那我们只需要求出第一个商人最大价值出现了几次(因为地方售价不相等,所以可以不会出现改一个地方售价影响两个最大价值的情况),然后改动他卖出或者出售地方售价就ok,毕竟求最小那么我们就只改动1就好 ,那么最小代价就变成了,最大利润出现的次数。
暴力跑肯定超时的,那么就在输入的时候算出来每个地方的利润,顺便记录最大值即可。
1 #include<iostream>
2 #include<math.h>
3 #include<cstdio>
4
5 using namespace std;
6
7 int dp[100005];
8 int main()
9 {
10 int n,t;
11 scanf("%d%d",&n,&t);
12 int minn = 0x3f3f3f3f;
13 int maxn = 0;
14 for(int i=0;i<n;i++)
15 {
16 int a;
17 scanf("%d",&a);
18 dp[i] = a - minn>=0?a - minn:0;
19 minn = min(a,minn);
20 maxn = max(dp[i],maxn);
21 }
22 int ans = 0;
23 for(int i = 0;i<n;i++)
24 {
25 if(maxn == dp[i])ans++;
26 }
27 printf("%d\n",ans);
28 }
View Code