Click Here to go back to the homepage.

Planting Trees Solution:


#include <bits/stdc++.h>
using namespace std;

int main(){
    // #ifndef TESTING
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    int nSeedlings;
    cin >> nSeedlings;

    priority_queue<int> q;
    while(nSeedlings--){
        int seedling;
        cin >> seedling;
        q.push(seedling);
    }
    int day = 2;
    int result = 0;
    while(q.size()){
        result = max(q.top() + day++, result);
        q.pop();
    }
    cout << result << endl;
    

    return 0;   
}