Skip to content

Instantly share code, notes, and snippets.

@roy4801
Created May 18, 2019 07:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roy4801/b417a1a65d2e43f3534f580a3bacd78d to your computer and use it in GitHub Desktop.
Save roy4801/b417a1a65d2e43f3534f580a3bacd78d to your computer and use it in GitHub Desktop.
單調列隊
#include <bits/stdc++.h>
using namespace std;
int t, n, maxv;
deque<int> dq;
int main(int argc, char *argv[])
{
cin >> t;
while(t-- && cin >> n)
{
maxv = INT_MIN;
dq.clear();
for(int i = 0, in; i < n && cin >> in; i++)
{
if(!dq.empty()) maxv = max(maxv, dq.front()-in);
while(!dq.empty() && dq.back() <= in)
dq.pop_back();
dq.push_back(in);
}
cout << maxv << '\n';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment