题目描述

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. liunx 安装 mysql 5.6

    第一步  解压文件 目录切换到/usr/local/ cd /usr/local/ 解压 tar zxvf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz 重命名为 ...

  2. SQL Server 数据恢复到指点时间点(完整恢复)

    SQL Server 数据恢复到指点时间点(完整恢复) 高文龙关注2人评论944人阅读2017-03-20 12:57:12 SQL Server 数据恢复到指点时间点(完整恢复) 说到数据库恢复,其 ...

  3. bat命令查询硬件信息

    bat命令查询硬件信息 50 需求是这样的写一个bat命令,当命令执行的时候,先请用户输入姓名,然后继续执行查询出以下信息并写入一个文件,文件名称随便,文件可以放在与当前命令同一个文件夹下.最终文件中 ...

  4. Confluence 6 当前使用的数据库状态

    进入  > 基本配置(General Configuration) > 问题检查和支持工具(Troubleshooting and support tools) 你就可以看到当前使用的数据 ...

  5. SpringBoot定时任务

    代码做定时任务:1.开个线程,线程里面休眠去做 2.使用一些定时任务的框架去做 1.创建TimerTest类 package com.cppdy.service; import org.springf ...

  6. servlet 乱码解决方法

    一. servlet 发送的html 页面中文乱码 解决方法, 1.加入如下代码 response.setCharacterEncoding("UTF-8"); 2.在html页面 ...

  7. arm指令1

    .section .text.writeFUNCTION(write) ldr r12, =__NR_write swi #0 bx lr LDR: LDR 的两种用法 1)LDR pc, =MyHa ...

  8. CF1015F

    玄学字符串dp... 题意:给定一个括号序列,求长度为2n的合法的括号序列的个数(要求每个被统计的合法序列中均至少有一个子串为给定的括号序列) 题解: 这题没有想的那么复杂,就是暴力的一个dp 首先我 ...

  9. python-中缀转换后缀并计算

    这个好像比较简单. 前缀规则好像还没有理清楚. # coding = utf-8 class Stack: def __init__(self): self.items = [] # 是否为空 def ...

  10. Windows无法自动将IP协议堆栈绑定到网络适配器 的解决办法

    实验室的台式机在升级驱动后上不了网了,有线网卡驱动卸载后重装了,还是不行,通过Windows诊断发现“Windows 无法自动将 IP 协议堆栈绑定到网络适配器的解决办法”. 解决办法: 打开“控制面 ...