PDP-31 (2019) - Camp juniors - 1 (max3sum)

View as PDF

Submit solution

Points: 30 (partial)
Time limit: 1.0s
Memory limit: 64M

Author:
Problem types
Allowed languages
C, C++, Java, Pascal, Python

Maximum Sum of Three

Three arrays, A, B, C, each consisting of N natural numbers are given. The task is to calculate the maximum value of the sum of three elements A_i+B_j+C_k where 0 \le i < j < k < N.

Input:

The first line of input will contain a natural number N: the size of each array. Each of the next three lines of input will contain N natural numbers: the elements of the three arrays.

Output:

The output should consist of a single line containing exactly one natural number: the desired maximum sum.

Note: All data is read from standard input and printed to standard output.

Constraints:
  • For subtasks worth 20% of total score, it holds:
    3 \le N \le 1000
  • For subtasks worth 40% of total score, it holds:
    3 \le N \le 10000
  • For subtasks worth 100% of total score, it holds:
    3 \le N \le 1000000
Example of Input - Output Files:
1st

STDIN

6
8 2 3 14 1 4
1 2 12 3 16 4
1 4 20 14 3 2

STDOUT

34

Explanation of the first example:

In the first example, the maximum sum is achieved by taking 8+12+14=34.


2nd

STDIN

10
2 4 6 8 10 12 15 18 21 25
1 2 30 3 4 35 6 7 28 12
50 45 40 35 30 25 20 15 10 5

STDOUT

69

Explanation of the second example:

In the second example, the maximum sum is achieved by taking 4+30+35=69.


Comments

There are no comments at the moment.