SC. Planting Trees


Submit solution

Points: 3 (partial)
Time limit: 1.0s
Memory limit: 98M

Author:
Problem type
Allowed languages
Ada, Assembly, Awk, C, C++, C11, CLANG, CLANGX, Classical, COBOL, Coffee, CSC, D lang, DART, F95, FORTH, Fortrn, GAS32, GO, Haskell, Itercal, Java, kotlin, LEAN, LISP, LUA, MONOVB, Nasm, OCAML, Pascal, Perl, php, PIKE, prolog, Pypy, Python, Ruby 2, RUST, Scala, SCM, SED, SWIFT, TCL, TUR, V8JS, VB, ZIG

Farmer Jon has recently bought \(n\) tree seedlings that he wants to plant in his yard. It takes one day for Jon to plant a seedling, and for each tree Jon knows exactly in how many days after planting it grows to full maturity. Jon would also like to throw a party for his farmer friends, but in order to impress them he would like to organize the party only after all the trees have grown. More precisely, the party can be organized at earliest on the next day after the last tree has grown up.

Help Jon to find out when is the earliest day when the party can take place.

Jon can choose the order of planting the trees as he likes, so he wants to plant the trees in such a way that the party will be as soon as possible.

Input

The input consists of two lines. The first line contains a single integer \(N\) \((1 ≤ N ≤ 100000)\) denoting the number of seedlings. Then a line with \(N\) integers \(t_i\) follows \((1 ≤ t_i ≤ 1000000)\), where \(t_i\) denotes the number of days it takes for the \(i\)-th tree to grow.

Output

You program should output exactly one line containing one integer, denoting the earliest day when the party can be organized. The days are numbered \(1, 2, 3,...\) beginning from the current moment.

Example 1

Input

4
2 3 4 3

Output

7

Example 2

Input

6
39 38 9 35 39 20

Output

42

Comments


  • 1
    TICHPX  commented on Oct. 14, 2021, 4:10 a.m.

    code tham khảo Python

    from sys import stdin
    if __name__ == '__main__':
        n,*a=list(map(int,stdin.read().split()))
        a.sort(reverse=True)
        print(2+max([i+x for i,x in enumerate(a)]))

  • 1
    NguyenDongThinh_CNTT4_K61  commented on Oct. 13, 2021, 5:54 a.m.

    Ai giải thích cho em về input với được không ạ


    • 3
      NguyenLoc_CNTT1_K61  commented on Oct. 13, 2021, 7:26 a.m. edit 4

      Tìm số ngày ngắn nhất để trồng các cây và trưởng thành, như vd 1 : có 4 cây mỗi cây cần làn lượt 2 3 4 3 ngày để trưởng thành. Thì đầu tiên trồng cây số 3 (cần 4 ngày để lớn), ngày số 2 trồng cây số 4 (cần 3 ngày để lớn), ngày số 3 trồng cây số 2(cần 3 ngày để lớn), ngày thứ 4 trồng cây số 1 (cần 2 ngày để lớn). Số ngày để trông và để trưởng thành các cây lần lượt là 5 4 4 3, do còn trùng ngày nên sẽ ra 7 ( vẽ hình ra dễ nhìn hơn). Tròng cây nào trước cũng được, cần 1 ngày trồng và a ngày lớn