跳到正文

题解

[ABC047D] 高橋君と見えざる手题解

_7Mr约 1 分钟
原文
文章信息与版本

文章信息

发布
2023年3月27日
收录
2025年12月12日
更新
2026年11月13日
篇幅
约 1 分钟

版本

  1. v1当前

基本思路

先不用管下降多少,先把所有的最大收益求出来

然后再遍历一遍,如果,当前的最大收益等于所有的最大收益那么给他下降 ans++

最后输出答案就行了

变量 & 数组介绍

sum[i] 当前的最大收益

mx 所有的最大收益

mn 当前最低价格

ans 答案记录

ACcode

C++
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int n,t,ans,mx=-2e9,mn=2e9;
int a[maxn],sum[maxn];
int main() {
	ios::sync_with_stdio(false);//加快cin cout
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>t;
	for(int i=1; i<=n; i++) cin>>a[i];
	for(int i=1; i<=n; i++) {
		sum[i]=a[i]-mn;
		mx=max(mx,sum[i]);
		mn=min(mn,a[i]);
	}
	for(int i=1;i<=n;i++) 
		if(sum[i]==mx) ans++;
	cout<<ans<<endl;
	return 0;
}
原文