Created
May 18, 2019 07:51
-
-
Save roy4801/b417a1a65d2e43f3534f580a3bacd78d to your computer and use it in GitHub Desktop.
單調列隊
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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