I was browsing r/dailyprogrammer, and I came across a challenge I thought I could figure out.

I'm not going to go into detail, but the gist of it is that there are plants that produce 1 fruit every week, with the amount of fruit they produce increasing by 1 every week. These produced fruits are planted to create more plants. The program runs until enough fruits are being produced so that 1 person gets at least 1 fruit in a population, the size of which is determined by the user.

The point here is the vector I'm using to hold the plants is causing a huge amount of lag and makes the program take ages to run. Here is the entire thing, annotated for easier comprehension:

```
#include <iostream>
#include <string>
#include <vector>

using namespace std;

void funnyPlant() {

    int startPlants, //initial plants (determined by user)
        people,      //population (determined by user)
        fruits = 0,  //fruits that the plants produce weekly
        week;        //integer representing time passed

    cout << "Enter population: ";
    cin >> people;
    cout << "Enter initial plant quanity: ";
    cin >> startPlants;
    vector<int> plant(startPlants); //vector is created with each element representing
                                    //1 plant, the value of which representing the amount
                                    //of fruit it produces in a given week

    cout << endl << "Processing, please wait..." << endl;

    for (week = 0; fruits < people; ++week) {
        fruits = 0; //fruits is reset because they are all planted immediately
        for (int i = 0; i < plant.size(); ++i) {

            fruits += plant[i]; //total fruits from each plant are tallied, to determine
                                //if there is enough for the given population

            ++plant[i]; //plant's fruit bearing capacity is increased by 1
        }
        for (int i = 0; i < fruits; ++i)
            plant.push_back(1); //each fruit is planted, increasing the size of the vector
    }

    cout << week << " weeks required for sustainability" << endl;
    cout << "( " << plant.size() << " plants producing " << fruits << " fruits)";
    cout << endl << endl;
}

int main() {

    funnyPlant(); //function is executed
    system("pause");
    return 0;
}

```

Now, the problem lies with my use of a vector to represent the amount of plants.

```
plant.push_back(1);

```

A higher population demands more time, which causes the amount of fruit being produced to reach astronomical quantities, which in turn causes the vector to expand to massive sizes, taking up a huge amount of memory.

Is there any way around this, or can I simply not use a vector? Any help would be greatly appreciated.