fdv

mail@pastecode.io avatar
unknown
plain_text
19 days ago
741 B
3
Indexable
Never
    int lowerbound(vector<int>& arr, int m, int target){
        int ans = m;
        int low = 0, high = m - 1;
        while(low <= high){
            int mid = (low + high) / 2;
            if(arr[mid] >= target){
                ans = mid;
                high = mid - 1;
            }
            else low = mid + 1;
        }
        return ans;
    }
    vector<int> rowAndMaximumOnes(vector<vector<int>>& mat) {
        int max_cnt = 0;
        int ind = -1;
        for(int i = 0; i < n; i++){
            int cnt_ones = m - lowerbound(mat[i], m, 1);
            if(cnt_ones > max_cnt){
                max_cnt = cnt_ones;
                ind = i;
            }
        }
        return {ind, max_cnt};
    }
Leave a Comment