#include <iostream>
#include <numeric>
#include <vector>
int main()
{
std::vector<int> kidHeights = { 1, 3, 6, 5, 6, 4, 2, 3 };
int numberOfKidsThatCanSeeToTheRight =
std::accumulate(kidHeights.rbegin(), kidHeights.rend(), 0,
[](int curKidCount, int curHeight) {
// assuming positive heights
static int curMaxHeight = 0;
if (curHeight > curMaxHeight) {
++ curKidCount;
curMaxHeight = curHeight;
}
return curKidCount;
});
std::cout << numberOfKidsThatCanSeeToTheRight << std::endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bnVtZXJpYz4KI2luY2x1ZGUgPHZlY3Rvcj4KCmludCBtYWluKCkKewogICAgc3RkOjp2ZWN0b3I8aW50PiBraWRIZWlnaHRzID0geyAxLCAzLCA2LCA1LCA2LCA0LCAyLCAzIH07CgogICAgaW50IG51bWJlck9mS2lkc1RoYXRDYW5TZWVUb1RoZVJpZ2h0ID0KICAgICAgICBzdGQ6OmFjY3VtdWxhdGUoa2lkSGVpZ2h0cy5yYmVnaW4oKSwga2lkSGVpZ2h0cy5yZW5kKCksIDAsCiAgICAgICAgICAgICAgICAgICAgICAgIFtdKGludCBjdXJLaWRDb3VudCwgaW50IGN1ckhlaWdodCkgewoKICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vIGFzc3VtaW5nIHBvc2l0aXZlIGhlaWdodHMKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRpYyBpbnQgY3VyTWF4SGVpZ2h0ID0gMDsKCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoY3VySGVpZ2h0ID4gY3VyTWF4SGVpZ2h0KSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKysgY3VyS2lkQ291bnQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY3VyTWF4SGVpZ2h0ID0gY3VySGVpZ2h0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBjdXJLaWRDb3VudDsKICAgICAgICAgICAgICAgICAgICAgICAgfSk7CgogICAgc3RkOjpjb3V0IDw8IG51bWJlck9mS2lkc1RoYXRDYW5TZWVUb1RoZVJpZ2h0IDw8IHN0ZDo6ZW5kbDsKfQ==