3 test cases failed

#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define DEBUG(x) cout << ‘>’ << #x << ‘:’ << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i–)
typedef long long ll;
int main()
{
ll n ,a[100000] , left[100000] = {0} ,right[100000] = {0} , mi[100000];

cin>>n;

REP(i,n){
   cin>>a[i]; 
}

int   high = INT_MIN ;
REP(i,n){
    if(a[i]>high)
       high = a[i];
       
       left[i] = high;
      
}
  high = INT_MIN ;

for(int i=n-1 ; i>=0 ; i--){
  if(a[i]>high)
       high = a[i];
       
       right[i] = high ;
      //  DEBUG(right[i])
}

 int count = 0 , ans = 0  ; 

REP(i,n){
    mi[i] = min(left[i],right[i]);
      count = mi[i]-a[i];
      ans+=count;
}
 cout<<ans<<endl;


return 0;

}

hello @StreamerX
make all ur array global and then try .

It shows error on making the variables global ! and why we are doing that ?

global scope has higher memory capacity than function scope thats why we r making them global.
please share ur updated code using cb ide so that i can check

#include <bits/stdc++.h> using namespace std; #define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define DEBUG(x) cout << ‘>’ << #x << ‘:’ << x << endl; #define REP(i,n) for(int i=0;i<(n);i++) #define FOR(i,a,b) for(int i=(a);i<=(b);i++) #define FORD(i,a,b) for(int i=(a);i>=(b);i–) typedef long long ll; long int n ,a[1000000] , left[1000000] = {0} ,right[1000000] = {0} , mi[1000000]; int main() { cin>>n; REP(i,n){ cin>>a[i]; } ll high = INT_MIN ; REP(i,n){ if(a[i]>high) high = a[i]; left[i] = high; } high = INT_MIN ; for(int i=n-1 ; i>=0 ; i–){ if(a[i]>high) high = a[i]; right[i] = high ; // DEBUG(right[i]) } ll count = 0 , ans = 0 ; REP(i,n){ mi[i] = min(left[i],right[i]); count = mi[i]-a[i]; ans+=count; } cout<<ans<<endl; return 0; }

save ur code here -> https://ide.codingblocks.com/
and share the link with me.

pls check this -> https://ide.codingblocks.com/s/253860

modifications
a) increased array size (10^6) because n can be upto 10^6
b) changed name of left to lef and right to righ(compiler was saying them as ambiguos varibale name)