fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int N;
  7. vector<int> trees;
  8. int currentDay = 2;
  9. int answer = 0;
  10.  
  11. int main() {
  12. ios::sync_with_stdio(0);
  13. cin.tie(0);
  14. cout.tie(0);
  15.  
  16. cin>>N;
  17. for(int i=0;i<N;i++){
  18. int tree;
  19. cin>>tree;
  20.  
  21. trees.push_back(tree);
  22. }
  23. sort(trees.begin(), trees.end(), greater<int>());
  24.  
  25. for(int i=0;i<N;i++){
  26. answer = max(answer, trees[i] + currentDay++);
  27. }
  28. cout<<answer<<'\n';
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0s 5280KB
stdin
6
39 38 9 35 39 20
stdout
42