#include <cstddef>
#include <iostream>
#include <limits>
#include <vector>

// Start a new sum; on rejection retain the last accepted partial sum.
// total is a separate object, not an element of values.
bool checked_sum(const std::vector<unsigned>& values, unsigned& total) {
    const unsigned M{std::numeric_limits<unsigned>::max()};
    total = 0;
    for (std::size_t i{0}; i < values.size(); ++i) {
        if (values[i] > M - total) {
            return false;
        }
        total += values[i];
    }
    return true;
}

int main() {
    const unsigned M{std::numeric_limits<unsigned>::max()};
    std::vector<unsigned> values{2u, 4u, 6u};
    std::vector<unsigned> empty{};
    std::vector<unsigned> single{M};
    std::vector<unsigned> overflow{M, 1u};
    unsigned total{0};
    bool accepted{checked_sum(values, total)};
    std::cout << accepted << ' ' << total << '\n';
    accepted = checked_sum(empty, total);
    std::cout << accepted << ' ' << total << '\n';
    accepted = checked_sum(single, total);
    std::cout << accepted << ' ' << (total == M) << '\n';
    accepted = checked_sum(overflow, total);
    std::cout << accepted << ' ' << (total == M) << '\n';
    return 0;
}
