Help me in solving HOSTELROOM problem

My issue

Why isn’t this logic not working?

My code

import java.util.*;
import java.lang.*;
import java.io.*;

class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-->0){
            int n=sc.nextInt(),x=sc.nextInt();
            int max=x,temp=0;
            ArrayList<Integer> arr=new ArrayList<>();
            for(int i=0;i<n;i++){
                temp=sc.nextInt();
                max=max+temp;
                
                arr.add(max);
            }
            System.out.println(Collections.max(arr));
        }
	}
}

Problem Link: Hostel Room Practice Coding Problem - CodeChef

@ashishprakashp
bro plzz refer my c++ code for better understanding of the logic

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

int main() {
	// your code goes here
    int t;
    cin>>t;
    while(t--)
    {
    int n,m;
    cin>>n>>m;
    int a[n];
    int cnt=m;
    int mx=max(mx,cnt);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        cnt+=a[i];
        mx=max(mx,cnt);
    }
    cout<<mx<<endl;
    }
}