Codeforces Books

The following code runs successfully on the USACO IDE, but it gives me a runtime error on codeforces with the exact same input and I have no idea why.

using namespace std;
int main(){
    int n,t;
    cin>>n>>t;

    vector<int> arr(n+1);
    for(int i=1;i<=n;i++) cin>>arr[i];

    int a=1,b=1,mx=0;
    long long s=0;

    for(int i=1;i<=n;i++){
        while(s+arr[b]<=t&&b<=n){
            s+=arr[b];
            b++;
        }
        mx=max(mx,b-a);
        s-=arr[a];
        a++;
    }
    cout<<mx;
}```

See the section on undefined behavior.