package max.algo; import max.obj.LongList; public class AlgoComplexe { public static Long compute(LongList in) { LongList tmp = new LongList(); // On simplifie la liste et on raccourcit les négatifs des bords int len = in.size(); Long tmpS = null; for(int i=0; i 0) { tmpS = tmpL; } else if(tmpS * tmpL >= 0) { tmpS += tmpL; } else if(tmpS * tmpL < 0){ tmp.add(tmpS); tmpS = tmpL; } } if(tmpS > 0) tmp.add(tmpS); // On enlève les bords si nécessaires int len2 = tmp.size(); int debut = 0; int fin = len2 - 1; while(debut < len2 - 1) { if(tmp.get(debut) + tmp.get(debut + 1) > 0) break; debut += 2; } while(fin > 0) { if(tmp.get(fin) + tmp.get(fin - 1) > 0) break; fin -= 2; } if(debut > 0 || fin < len2 - 1) { tmp = tmp.subList(debut, fin + 1); } // On applique l'algorithme de base return AlgoTrivial.compute(tmp); } }