The Java Program: MSS.java
1 // Maximum.java: Maximum sum subsequence (parallel version)
2
3 class Prefix implements Runnable {
4 int [] X, Y;
5 int i,k,m;
6 Prefix (int i, int k, int m) {
7 this.i=i;
8 }
9 void run () {}
10 }
11
12 class MSS {
13 static int X [] = { -4, 2, 6, -1, -7, 4, 2, -1 };
14 static int u,v=0;
15
16 public static void main (String args[]) {
17 int seen=X[0],here=X[0];
18 int q = 0;
19 for (int i=1; i<X.length; i++) {
20 if (here>=0) {
21 here = here + X[i];
22 } else {
23 here = X[i];
24 q = i;
25 }
26 if (seen<here) {
27 seen = here;
28 u = q;
29 v = i;
30 }
31 }
32 System.out.println ("u="+u+", v="+v+", max="+seen);
33 }
34 }