[codility]Falling-discs

// you can also use includes, for example:
// #include <algorithm>
#include<climits>
int solution(vector<int> &A, vector<int> &B) {
    // write your code in C++98
    //...first transform the dry well to a sorted one in decreasing order
    for(int i = 1; i < A.size(); ++i)
        A[i] = min(A[i], A[i-1]);
    //...for each disk find its place from bottom to top
    int result = 0;
    int i = 0;
    int j = A.size()-1;
    while(i < B.size())
    {
        while(j >= 0)
        {
            if(A[j] >= B[i])
            {
                result++;
                j--;
                break;
            }
            else j--;
        }
        ++i;
    }
    //...return result
    return result;
}

你可能感兴趣的:([codility]Falling-discs)