-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAssembly_line.cpp
73 lines (60 loc) · 1.47 KB
/
Assembly_line.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//2012004236_정구열
#include <stdio.h>
#include <stdlib.h>
#define MAX 100
#define MIN(a,b) ((a)>(b))?(b):(a)
int main() {
int i, j;
int n;
int e1, e2;
int x1, x2;
int a[2][MAX], t[2][MAX];
int S[2][2], L[2][MAX];
int path[MAX];
scanf("%d",&n);
scanf("%d %d", &e1, &e2);
scanf("%d %d", &x1, &x2);
for(i=0;i<2;i++){
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
}
for(i=0;i<2;i++){
for(j=0;j<n-1;j++)
scanf("%d",&t[i][j]);
}
S[0][0] = a[0][0] + e1;
S[1][0] = a[1][0] + e2;
for(i=0;i<n-1;i++){
S[0][1] = MIN(S[0][0] + a[0][i+1], S[1][0] + t[1][i] + a[0][i+1]);
S[1][1] = MIN(S[1][0] + a[1][i+1], S[0][0] + t[0][i] + a[1][i+1]);
if(S[0][1] == S[0][0] + a[0][i+1])
L[0][i+1] = 1;
else
L[0][i+1] = 2;
if(S[1][1] == S[1][0] + a[1][i+1])
L[1][i+1] =2;
else
L[1][i+1] = 1;
S[0][0] = S[0][1];
S[1][0] = S[1][1];
}
if(S[0][1] + x1>S[1][1] +x2){
L[1][n] = 2;
L[0][n] = -1;
printf("%d\n",S[1][1] + x2);
}
else{
L[1][n] = -1;
L[0][n] = 1;
printf("%d\n",S[0][1] + x1);
}
if(L[0][n] != -1)
path[n] = 1;
else
path[n] = 2;
for(i=n-1;i>0;i--)
path[i] = L[path[i+1]-1][i];
for(i=1;i<=n;i++)
printf("%d %d\n",path[i],i);
return 0;
}