|
1234567891011121314151617181920212223242526 |
- from SoSe24.algodat.foundation import AlgoDatArray, AlgoDatValue, read_int_sequence, MinusInf
- from time import perf_counter as pfc
-
- def maxfolge1(z: AlgoDatArray) -> (int, int, int):
- maximum = AlgoDatValue(MinusInf())
- current_sum = AlgoDatValue(0)
- left = AlgoDatValue(0)
- right = AlgoDatValue(0)
- for i in range(z.size):
- for j in range(i, z.size):
- current_sum.value = 0
- for k in range(i, j + 1):
- current_sum += z[k]
- if current_sum > maximum:
- maximum.value = current_sum.value
- left.value = i
- right.value = j
- return maximum.value, left, right
-
-
- if __name__ == "__main__":
- z = read_int_sequence("../../seq0.txt")
- start = pfc()
- print(maxfolge1(z))
- print(f"Dauer: {pfc() - start:.4f}s")
- AlgoDatValue.summary()
|