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;
}