Maximum element in a map c++

#include <iostream>
#include <map>

int main() {
    std::map<int, int> myMap;

    // Insert key-value pairs into the map
    myMap[1] = 10;
    myMap[2] = 20;
    myMap[3] = 30;
    myMap[4] = 40;

    // Initialize variables to track the maximum key and corresponding value
    int maxKey = myMap.begin()->first;
    int maxValue = myMap.begin()->second;

    // Iterate through the map to find the maximum element
    for (auto it = myMap.begin(); it != myMap.end(); ++it) {
        if (it->second > maxValue) {
            maxKey = it->first;
            maxValue = it->second;
        }
    }

    // Output the maximum key and value
    std::cout << "Maximum Key: " << maxKey << std::endl;
    std::cout << "Maximum Value: " << maxValue << std::endl;

    return 0;
}