Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** INDICATII:
- SE VA PARCURGE VECTORUL DE LA DREAPTA LA STâNGA
- SI SE VA AFLA DISTANTA MAXIMA DE LA POZITIA CURENTA
- LA POZITIA MAXIMULUI PANA LA ELEMENTUL DAT.*/
- #include <bits/stdc++.h>
- using namespace std;
- int num, arr[100005], t, sol;
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cin>>t;
- while(t)
- {
- cin >> num;
- arr[0]=2e9;
- for(int i=1; i <= num; i++)
- cin>>arr[i];
- stack<int>sc;
- sc.push(0);
- sol=0;
- for(int i=1; i <= num; i++)
- {
- while(!sc.empty() && arr[sc.top()] < arr[i])
- sc.pop();
- sol=max(sol, i - sc.top() - 1);
- sc.push(i);
- }
- cout<<sol<<'\n';
- t--;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment