Code:
#include<iostream>
#include<cstdlib>
#define max 1005
int a1[max];
int a2[max];
using namespace std ;
int main()
{
int n ;
int rezult ;
int E1 , E2 , X1 ,X2 ;
cin>>n ;
cin>>E1 >>E2 >>X1 >>X2 ;
int* p1 =new int[n];
int* p2 =new int[n];
int* T1 =new int[n-1];
int* T2 =new int[n-1];
int i = 0 ;
while(i<n)
cin>>p1[i++];
i=0;
while(i<n)
cin>>p2[i++];
i=0;
while(i<n-1)
cin>>T1[i++];
i=0;
while(i<n-1)
cin>>T2[i++];
int sum1 , sum2 ;
sum1 = a1[0]= E1+p1[0] ;
sum2 = a2[0]= E2+p2[0] ;
for(int i=0;i<n-1;i++)
{
a1[i+1]=a1[i]+p1[i+1];
sum1= a2[i]+T2[i]+p1[i+1];
a1[i+1] = sum1<a1[i+1]? sum1:a1[i+1];
a2[i+1]=a2[i]+p2[i+1];
sum2=a1[i]+T1[i]+p2[i+1];
a2[i+1]=sum2<a2[i+1]?sum2:a2[i+1];
}
delete [] p1 ,p2,T1,T2 ;
a1[n-1]=a1[n-1]+X1;
a2[n-1]=a2[n-1]+X2;
rezult = a1[n-1]<a2[n-1]?a1[n-1]:a2[n-1];
cout<<rezult<<endl;
system(“pause”);
return 0 ;
}
|