cielseven's picture
add 19 shard00 problems, update the algorithms, drop prim_forward_star
3805fe5
Raw History Blame Contribute Delete
867 Bytes
/*@ Extern Coq
(Forall : {A} -> (A -> Prop) -> list A -> Prop)
(Z::le : Z -> Z -> Prop)
(Z::ge : Z -> Z -> Prop)
(MaxSubarraySumPrefix : list Z -> Z -> Z -> Prop)
*/
/*@ Import Coq Require Import PVbench.Algorithms.maximum_subarray.rocq.spec_lib */
int max(int a, int b)
{
return (a > b) ? a : b;
}
int max_sub_array(int *arr, int n)
/*@ With (l : list Z)
Require
1 <= n && n <= 100000 &&
Zlength(l) == n &&
IntArray::full(arr, n, l) &&
Forall(Z::le(-10000), l) && Forall(Z::ge(10000), l)
Ensure
MaxSubarraySumPrefix(l, n, __return) &&
IntArray::full(arr, n, l)
*/
{
if (n == 0) {
return 0;
}
int cur = arr[0];
int res = arr[0];
for (int i = 1; i < n; i++) {
cur = max(arr[i], cur + arr[i]);
res = max(res, cur);
}
return res;
}