what is the difference in these codes?

pdoblem code : [CHEFSHOPPING]
my solution : (Wrong answer)
#include<bits/stdc++.h>
using namespace std;

int main() {
int t;
cin>>t;
while(t–) {
int N;
cin>>N;
int L[N],R[N];
int ans=0;
for(int i=0;i<N;i++) {cin>>L[i];}
for(int i=0;i<N;i++) {cin>>R[i];}
for(int i=0;i<N-1;i++){
ans+=min(R[i],L[i+1]);
}
cout<<ans<<endl;
}
return 0;
}

one of the user’s solution. (accepted)

#include <bits/stdc++.h>
using namespace std;

int main(){
long long int t;
cin>>t;
while(t–){
long long n;
cin>>n;
long long l[n],r[n];
long long ans=0;
for(long long i=0;i<n;i++)cin>>l[i];
for(long long i=0;i<n;i++)cin>>r[i];
for(long long i=0;i<n-1;i++){
ans+=min(l[i+1],r[i]);
}
cout<<ans<<endl;
}
}

i dont understand the reason why im getting wrong answer. code is exactly the same. (pls dont tell im copying. i would not be here and asking this question if i were copying)

kindly help me

overflow ,use long long instead of int