USACO 2018 December Contest, Bronze Problem 2. The Bucket List exceeded memory limit

My code seems to exceed the memory limit. Is there any modifications I can make?



#include <iostream>

int main()
{
    int max_element = 0;
    int total = 0;
    int n;
    int max = 0;
    std::cin >> n;
    int starts[100];
    int ends[100];
    int buckets[100];
    
    freopen("blist.in", "r", stdin);
    // the following line creates/overwrites the output file
    freopen("blist.out", "w", stdout);
    for (int x = 0; x < n; x++) {
        std::cin >> starts[x];
        std::cin >> ends[x];
        std::cin >> buckets[x];

    }
    for (int i = 0; i < n; ++i) {
        if (ends[i] > max_element) {
            max_element = ends[i];
        }
    }
    for (int z=0; z < max_element; z++) {
        for (int x=0; x < n; x++) {
            
            if (z >= starts[x]) {
                if (z <= ends[x]) {
                    total =  total+buckets[x];
                }
            }
            
            if (total >= max) {
                max = total; 
                
            }
            
            
        }
        //std::cout << total << ' ';
        total = 0;
    }
    std::cout << max;
}

Um, do you check that your code actually produces the correct output before submitting it? Because it definitely does not work on the sample …

hmm it seems to work here
Capture

How are you running your code?

The issue is that you are not reading n from the input file …