264602026-03-28 23:02:32kukkermanLegtöbb gyümölcs (40 pont)cpp17Elfogadva 40/402ms756 KiB
#include <iostream>
#include <string>
#include <algorithm>

std::string beolvas(std::istream &be = std::cin) {
    int n;
    be >> n;

    std::string gy;
    be >> gy;

    return gy;
}

int legtobb_gyumolcs(const std::string &gy) {
    const int n = static_cast<int>(gy.size());

    int a = 0;
    int k = static_cast<int>(std::count(gy.begin(), gy.end(), 'K'));
    for (int i = 0; i < n && a < k; i++) {
        a += gy[i] != 'K';
        k -= gy[i] == 'K';
    }

    return a << 1;
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);

    const auto gy = beolvas();
    std::cout << legtobb_gyumolcs(gy) << '\n';

    return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base40/40
1Elfogadva0/01ms316 KiB
2Elfogadva0/01ms756 KiB
3Elfogadva2/21ms316 KiB
4Elfogadva2/21ms316 KiB
5Elfogadva2/21ms324 KiB
6Elfogadva2/21ms316 KiB
7Elfogadva2/21ms508 KiB
8Elfogadva3/31ms316 KiB
9Elfogadva3/31ms316 KiB
10Elfogadva3/31ms508 KiB
11Elfogadva3/31ms316 KiB
12Elfogadva3/31ms316 KiB
13Elfogadva3/31ms508 KiB
14Elfogadva3/31ms564 KiB
15Elfogadva3/32ms564 KiB
16Elfogadva3/31ms564 KiB
17Elfogadva3/31ms564 KiB