Last active
May 21, 2018 04:51
-
-
Save mishal23/79930b304c8af1abc14858c0481eba60 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
/* | |
Problem:- Save Gotham! | |
Link:- https://practice.geeksforgeeks.org/problems/save-gotham/0 | |
Author:- Mishal Shah | |
*/ | |
#include "bits/stdc++.h" | |
#define MOD 1000000001 | |
using namespace std; | |
int main() | |
{ | |
int t; | |
cin>>t; | |
while(t--) | |
{ | |
int i,j,n; | |
long long sum=0; | |
cin>>n; | |
int a[n]; | |
stack<int> b; | |
for(i=0;i<n;i++) | |
{ | |
cin>>a[i]; | |
} | |
for(i=0;i<n;i++) | |
{ | |
if(i==0) | |
{ | |
b.push(a[i]); | |
} | |
else | |
{ | |
if(a[i]>b.top()) | |
{ | |
while(!b.empty() && a[i]>b.top()) | |
{ | |
//cout<<sum<<" "; | |
sum = (sum%MOD + a[i]%MOD)%MOD; | |
b.pop(); | |
} | |
} | |
b.push(a[i]); | |
} | |
} | |
cout<<sum<<endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment