Rain water trap problem

i am not able to come up with the right code please help me out here

#include<bits/stdc++.h> using namespace std; int raintrap(int a[], int n) { int left=0; int right=n-1; int newright=n-1; int leftmax=INT_MIN; int rightmax=INT_MIN; int water=0; int i=0; int rt[1000]; for(int j=n-1; j>=0; j++) { rightmax=max(rightmax, a[newright]); rt[i]=rightmax; newright–; } while(left!=n) { leftmax=max(leftmax, a[left]); water += min(leftmax,rt[i])-a[i]; left++; right–; i++; } /int total=0; for(int i=0; i<n; i++) { total += min(left, right)-a[i]; }/ return water; } int main() { int n; cin>>n; int a[1000]; for(int i=0; i<n; i++) { cin>>a[i]; } cout<<raintrap(a, n)<<endl; return 0; }