Algorithms and Data Structures

  • Profound Academy

    • Status
      • 1
        Implementation
      • 2
        Bitwise operations
      • 3
        Prefix Sums
      • 4
        Sliding window / Two pointers
      • 5
        Modular Arithmetic
      • 6
        Number Theory
      • 7
        Binary Search
      • 8
        Basic Sorting
      • 9
        Greedy Algorithms
      • 10
        Basic Dynamic Programming
      • 11
        Recursion
      • 12
        Linked LIst
      • 13
        Queue & Stack
      • 14
        Binary tree + BST
      • 15
        Divide & Conquer + Advanced Sorting
      • 16
        Heap
      • 17
        Hashing
      • 18
        Graph Representation
      • 19
        BFS

  • Two computers

    Two computers need to process n tasks - they need to process data from datasets. Each task takes time to complete. Each of the computers needs to process all the n tasks. Yet, whenever one computer works on a dataset, another one is not able to access it. You want to make sure the work is done as fast as possible.

    Input

    The first line of the input contains a single integer n (2 ≀ n ≀ ).
    The next line contains n space-separated integers (1 ≀ ≀ ) the time it takes to complete each task.

    Output

    The program should print the minimal time required to complete all the tasks for both computers.

    Examples

    Input
    Output
    4 4 9 1 2
    18

    Explanation

    The first computer processes tasks with durations 1, 2, and 4 (7 in total), while the second one processes the task with duration 9. After finishing it, the second one starts processing the tasks with durations 1, 2, and 4, while the first one starts working on the task with duration 9. Therefore, the total time to complete all the tasks for both computers is 18.

    Constraints

    Time limit: 1 seconds

    Memory limit: 512 MB

    Output limit: 1 MB

    To check your solution you need to sign in
    Sign in to continue