learningtrack

Learning Track

The winner of a student competition received internship offers from two universities.

While preparing his plans of study, he learned the teaching quality rating of each discipline at these universities.

The curriculum of the first university consists of a sequence of n different disciplines listed in chronological order a1,a2,,an, with ratings x1,x2,,xn respectively. The second university's curriculum also consists of a sequence of m different disciplines listed in chronological order b1,b2,,am, with ratings y1,y2,,ym respectively.

The student has the option of making a plan of study at the first university to take some sequence of disciplines at curriculum positions la through ra inclusive (1laran), or decline an internship at the first university. Similarly, he or she may plan to study some disciplines lb through rb inclusive (1lbrbm) in the second university, or decline the internship at the second university.

It does not make sense to study the same discipline twice at different universities, so all the disciplines in the two chosen plans of study must be different.

Write a program to determine the highest possible sum of ratings of the studied disciplines, given the student makes an optimal study plan.

Limits

1n,m5105, 1ai,bin+m, aiaj, bibj, 1xi,yi109

Subtask # Score Constraints
1 10 n,m50
2 10 n,m100
3 10 n,m300
4 10 n,m500
5 10 n,m2000
6 5 n,m5000
7 5 n,m10000
8 10 n,m30000
9 10 n,m100000
10 10 n,m250000
9 10 No additional constraints

Input format

The first line of input contains integers n and m - the number of disciplines in the first and second university degree programs respectively (1n,m500,000).

The second line of input contains n integers ai - the disciplines included in the first university's curriculum, listed in chronological order (1ain+m).

The third line of input contains n integers xi - the ratings of the disciplines included in the first university's curriculum, listed in the same order as the disciplines ai (1xi109).

The fourth line of input contains m integers bi - the disciplines included in the second university's curriculum, listed in chronological order (1bin+m).

The fifth line of input contains m integers yi - the ratings of the disciplines included in the of the second university's curriculum, listed in the same order as the disciplines bi (1yi109).

Output format

The first line of output should contain an integer s - the largest possible sum of discipline ratings.

The second line of output should contain two integers la, ra - the range of courses chosen from the curriculum of the first university, or "0 0" if the student declined an internship at the first university.

The third line of output should contain two integers lb, rb - the range of courses chosen from the curriculum of the second university, or "0 0" if the student declined an internship at the second university.

If there are several possible answers, you may output any one of them.

Samples

Sample Input 1 Sample Output 1
7 5
3 1 4 8 6 9 2
2 7 4 10 1 5 3
9 2 11 3 8
3 5 3 4 12
39
2 6
2 4

The optimal solution is to take the courses described in the output, yielding a sum of ratings of (7+4+10+1+5)+(5+3+4)=27+12=39. One suboptimal combination which could have been taken is (7+4)+(3+5+3+4+12)=11+27=38.

Sample Input 2 Sample Output 2
2 3
1 2
1 4
2 3 1
17 2 15
34
0 0
1 3

In this testcase, the first and third disciplines at the second university are rated so highly compared to the corresponding disciplines at the first university, that the optimal choicen is to take the entire internship at the second university and forgo an internship at the first university.

Sample Input 3 Sample Output 3
3 3
4 2 1
10 1 2
5 4 2
1 2 9
19
1 1
3 3


Submitting to 'learningtrack'


You're not logged in! Click here to login


Submitting to 'learningtrack'


You're not logged in! Click here to login


Submitting .cpp to 'learningtrack'


You're not logged in! Click here to login

Time Limit: 5 Seconds
Memory Limit: 512MB
Your best score: 0
Source: LOJ #2773

Subtask Score
1 10
2 10
3 10
4 10
5 10
6 5
7 5
8 10
9 10
10 10
11 10
12 0