社区讨论
不能理解,为什么WA一个点?
P5146最大差值参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @lo2x4wd4
- 此快照首次捕获于
- 2023/10/23 21:13 2 年前
- 此快照最后确认于
- 2023/10/23 21:13 2 年前
CPP
#include <iostream>
#include <string>
#include <queue>
#include <limits.h>
#include <algorithm>
using namespace std;
const int N = 2e6 + 10;
typedef long long ll;
ll n , a[N] , q[N] , res;
int main()
{
cin >> n;
for (int i = 1 ; i <= n ; ++i) cin >> a[i];
int hh = 0 , tt = -1 ;
res = -0x3f3f3f3f;
for (int i = 1 ; i <= n ; ++i)
{
if(hh <= tt) res = max(res , a[i] - a[q[hh]]);
while(hh <= tt && a[q[tt]] >= a[i]) tt--;
q[++tt] = i;
}
cout << res << endl;
return 0;
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...