F-laurenty and ShopTime
limit:1000MS
Memory Limit:262144KB
64bit IO Format:%i64d &%i6 4u SubmitStatusPracticecodeforces 586B
Description
A little boy Laurenty had been playing his favourite game Nota for quite a while and was now very hungry. The boy wants to make sausage and cheese sandwiches, but first, he needs to buy a sausage and some cheese.
The town where Laurenty lives in are not large. The houses in it is located in and rows, n houses in each row. Laurenty lives in the very last House of the the second row. The only shop in town are placed in the first house of the first row.
The first and second rows is separated with the main avenue of the city. The adjacent houses of one row is separated by streets.
Each crosswalk of a street or an avenue has some traffic lights. In order to cross the street, you need to press a button on the traffic light, wait for a while for the green light and CR OSS the street. Different traffic lights can have Different waiting time.
The traffic light on the crosswalk from The J -th House of The i -th row to The ( j + 1)-th House of the same row have waiting time E Qual to a ij ( 1≤ i ≤ 2, 1≤ j ≤ n -1). For the traffic light on the crossing from The J -th House of one row to The J -th House of another row the waiting time Equals b Sub class= "Lower-index" > J (1≤ j ≤ n ). The city doesn ' t has any other crossings.
The boy wants to the store, buy the products and go back. The main avenue of the city was wide enough, so the boy wants to cross it exactly once on the the "the" to thestore and E Xactly once on the the-back home. The boy would get bored if he had to walk the same it again, so he wants the the-the-the-I-be-different from the the-the-the- Store in at least one crossing.
Figure to the first sample.
Help Laurenty determine the minimum total time he needs to wait at the crossroads.
Input
The first line of the input contains integer n (2≤ n ≤50)-the number of houses in each row.< /c5>
Each of the next lines contains n -1 space-separated integer-values aij ( 1≤ a ij ≤100).
The last line contains n space-separated integers bJ (1≤ b J ≤100).
Output
Print A single integer-the least total time laurenty needs to wait on the crossroads, given that he crosses the Avenue O Nly once both on his-to-the-store and on his-the-back home.
Sample Input
Input
4
1 2 3
3 2 1
3 2 2 3
Output
12
Input
3
1 2
3 3
2 1 3
Output
11
Input
2
1
1
1 1
Output
4
Hint
The first sample is shown on the above.
In the second sample, Laurenty's path can look as follows:
- Laurenty crosses the avenue, the waiting time is 3;
- Laurenty uses the second crossing in the first row, the waiting time is 2;
- Laurenty uses the first crossing in the first row, and the waiting time is 1;
- Laurenty uses the first crossing in the first row, and the waiting time is 1;
- Laurenty crosses the avenue, the waiting time is 1;
- Laurenty uses the second crossing in the second row, the waiting time is 3.
In total we get that the answer equalsOne by one .
The last sample Laurenty visits all the crossings and so the answer is 4.
Thought that through the main road can only once, so the total has a different way of the main road, direct violence, choose the smallest two on the line.
#include <iostream>#include<stdio.h>#include<algorithm>#defineINF 0x7fffffffusing namespacestd;intMain () {inta[2][ the]; intb[ the]; intN; scanf ("%d",&N); intsum=0; for(intI=0; i<n-1; i++) {scanf ("%d", &a[0][i]); //Sum+=a[0][i]; } for(intI=0; i<n-1; i++) {scanf ("%d", &a[1][i]); Sum+=a[1][i]; } intans[3]={Inf,inf,inf}; for(intI=0; i<n;i++) scanf ("%d",&B[i]); Sum+=b[0]; ans[0]=sum; for(intI=1; i<n;i++) {sum=sum-b[i-1]+B[i]; Sum=sum-a[1][i-1]+a[0][i-1]; ans[2]=sum; Sort (Ans,ans+3); //cout<<ans[0]<< "" <<ans[1]<<endl;} printf ("%d\n", ans[0]+ans[1] ); return 0;}
View Code
Codeforces 586B Laurenty and Shop