Skip to content

Instantly share code, notes, and snippets.

@gunavaran
Created October 17, 2020 13:40
Show Gist options
  • Save gunavaran/cb4cc012c14b657c6b5bbd6f66854fbe to your computer and use it in GitHub Desktop.
Save gunavaran/cb4cc012c14b657c6b5bbd6f66854fbe to your computer and use it in GitHub Desktop.
#include <stdint.h>
#include <stdbool.h>
bool overflow(int64_t *A, size_t n) {
//All elements of A are non-negative
A[n] = INT64_MAX;
A[n + 1] = 1; //any positive value
size_t i = 0;
int64_t sum = A[0];
while (sum >= A[i]) {
sum += A[++i];
}
if (i < n) return true;
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment