Help me in solving TREATS problem

My issue

this is my approach and its showing time limit exceed;
//code//
include <bits/stdc++.h>
using namespace std;

int main() {
int t;
int count;
int n,m;
cin>>t;
while(t–){
count=0;

    cin>>n>>m;
    int a[n];
    int b[n];
    for(int i=0 ; i<n;i++){
        cin>>a[i];
        
    }
    for(int i=0 ; i<n;i++){
        cin>>b[i];
    }
    for(int i=0; i<n;i++){
        for(int j=0;j<n;j++){
            if((a[i]+b[j])%m==0){
                count++;
            }
        }
    }
    cout<<count<<endl;
}

}

Problem Link: https://www.codechef.com/problems/TREATS

@anon55414147
here 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],b[n];
	    unordered_map<int,int> mp;
	    for(int i=0;i<n;i++)
	    {
	        cin>>a[i];
	        mp[a[i]%m]++;
	    }
	    long long int ans=0;
	    for(int i=0;i<n;i++)
	    {
	        cin>>b[i];
	        int val=m-b[i]%m;
	        if(val==m)
	        val=0;
	        ans+=mp[val];
	    }
	    
	    cout<<ans<<endl;
	}

}

> Blockquote