Download benchmarks/Algorithms/maximum_subarray/rocq/solution_spec.c from PV-SJTU/PV-Bench: direct link, hf CLI and curl.
- Browser
- Download file 867 Bytes
-
https://huggingface.co/datasets/PV-SJTU/PV-Bench/resolve/main/benchmarks/Algorithms/maximum_subarray/rocq/solution_spec.c
- Command line
-
hf download hf://datasets/PV-SJTU/PV-Bench/benchmarks/Algorithms/maximum_subarray/rocq/solution_spec.c
-
curl -L -o solution_spec.c https://huggingface.co/datasets/PV-SJTU/PV-Bench/resolve/main/benchmarks/Algorithms/maximum_subarray/rocq/solution_spec.c
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; | |
| } | |