题目描述

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.

输入

The input is given from Standard Input in the following format:
N T
A1 A2 … AN

输出

Print the minimum total cost to decrease Takahashi's expected profit by at least 1 yen.

样例输入

3 2
100 50 200

样例输出

1

提示

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就好 ,那么最小代价就变成了,最大利润出现的次数。

暴力跑肯定超时的,那么就在输入的时候算出来每个地方的利润,顺便记录最大值即可。

 #include<iostream>
#include<math.h>
#include<cstdio> using namespace std; int dp[];
int main()
{
int n,t;
scanf("%d%d",&n,&t);
int minn = 0x3f3f3f3f;
int maxn = ;
for(int i=;i<n;i++)
{
int a;
scanf("%d",&a);
dp[i] = a - minn>=?a - minn:;
minn = min(a,minn);
maxn = max(dp[i],maxn);
}
int ans = ;
for(int i = ;i<n;i++)
{
if(maxn == dp[i])ans++;
}
printf("%d\n",ans);
}

问题 L: An Invisible Hand - (2018年第二阶段个人训练赛第三场)的更多相关文章

  1. 2018牛客网暑假ACM多校训练赛(第二场)E tree 动态规划

    原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round2-E.html 题目传送门 - 2018牛客多校赛第二场 E ...

  2. 2019年第二阶段我要变强个人训练赛第八场 B.序列(seq)

    传送门 B.序列(seq) •题目描述 给出一个长度为n的序列a,每次对序列进行一下的某一个操作. •输入 第一行两个整数n,q表示序列长度和操作个数. 接下来一行n个数,表示序列a. 接下来q行表示 ...

  3. EZ 2018 03 09 NOIP2018 模拟赛(三)

    最近挺久没写比赛类的blog了 链接:http://211.140.156.254:2333/contest/59 这次的题目主要考验的是爆搜+打表的能力 其实如果你上来就把所有题目都看过一次就可以知 ...

  4. UPC 2019年第二阶段我要变强个人训练赛第六场

    传送门 A.上学路线 题目描述 小D从家到学校的道路结构是这样的:由n条东西走向和m条南北走向的道路构成了一个n*m的网格,每条道路都是单向通行的(只能从北向南,从西向东走). 已知小D的家在网格的左 ...

  5. 2018牛客网暑假ACM多校训练赛(第三场)I Expected Size of Random Convex Hull 计算几何,凸包,其他

    原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round3-I.html 题目传送门 - 2018牛客多校赛第三场 I ...

  6. 2018牛客网暑假ACM多校训练赛(第三场)G Coloring Tree 计数,bfs

    原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round3-G.html 题目传送门 - 2018牛客多校赛第三场 G ...

  7. 2018牛客网暑假ACM多校训练赛(第三场)D Encrypted String Matching 多项式 FFT

    原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round3-D.html 题目传送门 - 2018牛客多校赛第三场 D ...

  8. 2018 HDU多校第三场赛后补题

    2018 HDU多校第三场赛后补题 从易到难来写吧,其中题意有些直接摘了Claris的,数据范围是就不标了. 如果需要可以去hdu题库里找.题号是6319 - 6331. L. Visual Cube ...

  9. Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) (前三题题解)

    这场比赛好毒瘤哇,看第四题好像是中国人出的,怕不是dllxl出的. 第四道什么鬼,互动题不说,花了四十五分钟看懂题目,都想砸电脑了.然后发现不会,互动题从来没做过. 不过这次新号上蓝名了(我才不告诉你 ...

随机推荐

  1. 【MySql】Group By数据分组

    GROUP BY 语句根据一个或多个列对结果集进行分组. 在分组的列上我们可以使用 COUNT, SUM, AVG,等函数. 因为聚合函数通过作用于一组数据而只返回一个单个值, 因此,在SELECT语 ...

  2. 解决 安装或卸载软件时报错Error 1001 的问题

    卸载或安装程序时出错1001:错误1001可能发生在试图更新.修复或卸载windows os中的特定程序时.此问题通常是由于程序的先前安装损坏而引起的. 错误“1001”通常会遇到,因为程序的先前安装 ...

  3. 最短路径之Bellman-Ford算法

    第一行为源点个数,边的个数m 接下来m行为a->b和权值 5 52 3 21 2 -31 5 54 5 23 4 3 Bellman-Ford算法(1): #include<iostrea ...

  4. k倍区间

    看大佬的代码看了半天,终于算是懂了 标题: k倍区间 给定一个长度为N的数列,A1, A2, … AN,如果其中一段连续的子序列Ai, Ai+1, … Aj(i <= j)之和是K的倍数,我们就 ...

  5. MySQL----数据库简单操作

    启动服务 net start mysql57断开服务 net stop mysql57连接服务 mysql -u root -p断开连接 exit|quit查看版本 select version(); ...

  6. AI学习吧-结算中心

    结算中心流程 在结算中心中,主要是对用户添加到购物车商品的结算,由于用户可能添加了多个课程,但是,结算时会选择性的进行支付.在结算时会选中课程id,和对应的价格策略.在后台,首先会对用户进行校验,验证 ...

  7. 改变input type="file" 文字、样式等

    <div class="tac"> <input type="file" id="browsefile" class=&q ...

  8. Caused by: java.net.ConnectException: Connection refused/Caused by: java.lang.RuntimeException: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

    1.使用sqoop技术将mysql的数据导入到Hive出现的错误如下所示: 第一次使用命令如下所示: [hadoop@slaver1 sqoop--cdh5.3.6]$ bin/sqoop impor ...

  9. Quartz.net入门

    简介 Quartz.NET是一个开源的作业调度框架,是OpenSymphony的 Quartz API的.NET移植,它用C#写成,可用于winform和asp.net应用中.它提供了巨大的灵活性而不 ...

  10. Jmeter入门(压力测试)

    Jmeter介绍 Jmeter是一款使用Java开发的,开源免费的,测试工具, 主要用来做功能测试和性能测试(压力测试/负载测试). 而且用Jmeter 来测试 Restful API, 非常好用. ...