Somehow worked, help me optimise the code!
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int minimumTime(vector<int>& nums1, vector<int>& nums2, int x) {\n        \n        int n,m,i,j,sum;\n        \n        n=nums1.size();\n        if(n==0)return 0;\n        if(n==1){\n            if(nums1[0]<=x)return 0;\n            return 1;\n        }\n        \n        sum=0;\n    vector <pair<int,int> > v1(n);\n    for(i=0;i<n;i++)\n    {\n    v1[i].first=nums1[i];\n    v1[i].second=nums2[i];\n     sum+=v1[i].first;   \n    }\n        sort(v1.begin(),v1.end(),mysort);\n    \n        if(sum<=x)return 0;\n        \n      int p=  bnsh(1,n,x,v1,n); \n        for(i=max(1,p-10);i<=p;i++)\n        if(helper(v1,i,n,x)){\n            return i;\n        }\n        return -1;\n        \n        \n    }\n    \n    \n    int bnsh(int l , int r ,int x, vector <pair<int,int> > &v1, int n){\n        int mid;\n     mid=(l+r)/2;\n        \n        \n     while(l<=r){\n     mid=(l+r)/2;  \n      //cout<<"l r "<<l<<" "<<r<<" \\n";\n     if(helper(v1,mid,n,x)){\n        // cout<<"true for mid : "<<mid<<" \\n";\n     if(mid==l || !helper(v1,mid-1,n,x))return mid;\n      r=mid-1;   \n     }\n     else {\n     l=mid+1;      \n     }    \n           \n     }   \n          \n    return -1;    \n        \n    }\n    \n    \n    \n    static bool mysort(pair<int,int> a, pair<int,int> b){\n        if(a.second==b.second)\n        return a.first>b.first;\n        return a.second>b.second;\n    }\n    \n bool helper(vector <pair<int,int> > &v1, int t, int n , int x){\n  int i,j,sum; sum=0;   \n  \n     for(i=0;i<n;i++){\n     sum=sum +(v1[i].first + t*(v1[i].second));    \n     }\n  if(t<=0 || n<1)return (sum<=x);\n     \n       //cout<<"sum :"<<sum<<"\\n";\n  vector<vector <int> > discount(n,vector <int>(t,0));\n  \n  discount[0][0]=v1[0].first + t*(v1[0].second);   \n  for(i=1;i<n;i++){\n  discount[i][0]=max(discount[i-1][0],v1[i].first + t*(v1[i].second));  //base case    \n  }   \n     \n  for(i=1;i<n;i++){\n      for(j=1;j<=min(i,t-1);j++){\n     if(i==j){\n     discount[i][j]=discount[i-1][j-1] + (t-j)*v1[i].second + v1[i].first ;    \n     } \n    else discount[i][j] = max(discount[i-1][j], (discount[i-1][j-1] + (t-j)*v1[i].second + v1[i].first));          \n      \n     }\n      //cout<<"\\n";\n  }\n  \n     \n     \n  sum-=discount[n-1][t-1];   \n  \n  //cout<<"sum :"<<sum<<"\\n";   \n     return (sum<=x);\n     \n }   \n    \n    \n};\n```
['C++']