Help me in solving BALL_GAME problem

My issue

which concept applies here?

My code

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

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	    int n;
	    cin>>n;
	    vector<int>arr(n),speed(n);
	    vector<int>tot(n,1);
	    for(int i=0;i<n;i++){
	        cin>>arr[i];
	    }
	    for(int i=0;i<n;i++){
	        cin>>speed[i];
	    }
	    vector<int>time_(n);
	    vector<pair<int,int>>vec(n);
	    for(int i=0;i<n;i++){
	        vec[i]={arr[i],speed[i]};
	    }
	    sort(vec.begin(),vec.end());
	    for(int i=0;i<n;i++){
	        time_[i]=vec[i].first/vec[i].second;
	    }
	    
	    
	    for(int i=1;i<n;i++){
	        if(time_[i]<time_[i-1]){
	            int d1=vec[i-1].first;
	            int d2=vec[i].first;
	            int s1=vec[i-1].second;
	            int s2=vec[i].second;
	            int t=(d2-d1)/(s2-s1);
	            int s=max(s1,s2);
	            int d=d1-t*s1;
	            t=d/s+t;
	            time_[i]=t;
	            tot[i]=tot[i-1];
	        }
	        else {
	            tot[i]=tot[i-1]+1;
	        }
	    }
	    cout<<n-tot[n-1]+1<<endl;
	}

}

Problem Link: Ball Game Practice Coding Problem