Determining whether a string is transformable into another by repetitively increasing its prefixes alphabetically
Code review

In general, the code looks nice and follows consistent styles.  Some small observations:


Missing #include &lt;string&gt;.
Avoid std::endl when \n suffices.  std::endl flushes the buffer, while \n does not.  Unnecessary flushing can cause performance degradation.  See std::endl vs \n.  Use

std::cout &lt;&lt; "YES\n";


instead of

std::cout &lt;&lt; "YES" &lt;&lt; std::endl;


unless flushing is a requirement from the website (I hope not).
Since we are depending on lowercase letters being continuously encoded anyway, 'B' - 'A' is just 1.  And A[i] += 1 becomes ++A[i].


Better algorithm

That said, the logic of the code is overly convoluted.  The many levels of nested control statements make it hard to follow the code.  There is a much simpler algorithm to do it: to determine whether A is transformable into B,


take the differences between the corresponding positions B[i] - A[i];
form a sequence out of these differences;
append the sequence by 0 (to prevent cases like bbbbb =&gt; aaaaa);
test if this sequence is sorted in non-ascending order.


For example:


for A = "abcde", B = "ccdde", the sequence of differences is 21100, so the transformation is possible (abcde =&gt; bcdde =&gt; ccdde);
for A = "abcde", B = "bbcce", the sequence of differences is 10010, so the transformation is impossible (try it).


Here's (roughly) how I would put everything together:

#include &lt;algorithm&gt;
#include &lt;functional&gt;
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;string_view&gt;
#include &lt;vector&gt;

bool transformable(std::string_view a, std::string_view b)
{
    if (a.size() != b.size()) {
        return false;
    }
    std::vector&lt;int&gt; diff_sequence(a.size() + 1);
    std::transform(b.begin(), b.end(), a.begin(), diff_sequence.begin(), std::minus&lt;&gt;{});
    diff_sequence.back() = 0;
    return std::is_sorted(diff_sequence.begin(), diff_sequence.end(), std::greater&lt;&gt;{});
}

int main()
{
    std::string A;
    std::string B;

    std::cin &gt;&gt; A &gt;&gt; B;

    if (transformable(A, B)) {
        std::cout &lt;&lt; "YES\n";
    } else {
        std::cout &lt;&lt; "NO\n";
    }
}


(live demo)

(Replace std::string_view with const std::string&amp; and remove the #include &lt;string_view&gt; if C++17 is not available, which IIRC is the case with competitive programming sites.)

The transformable function can be simplified with the range-v3 library:

namespace views = ranges::views;

bool transformable(std::string_view a, std::string_view b)
{
    return ranges::is_sorted(
        views::concat(
            views::transform(b, a, std::minus&lt;&gt;{}),
            views::single(0)
        ), std::greater&lt;&gt;{});
}


(live demo)