diff options
| author | Aditya Naik | 2020-06-18 23:39:46 -0400 |
|---|---|---|
| committer | Aditya Naik | 2020-06-18 23:39:46 -0400 |
| commit | c0e0f5072822eb6372a1bd296a554482af97f77b (patch) | |
| tree | 321414dd0a0eb5436e8df12a62c6450f0f3b1412 /11264/coin.c | |
| parent | 36e8897c90442cd558cdddf3f2ae38f148ac5581 (diff) | |
Diffstat (limited to '11264/coin.c')
| -rw-r--r-- | 11264/coin.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/11264/coin.c b/11264/coin.c new file mode 100644 index 0000000..2fa2dbb --- /dev/null +++ b/11264/coin.c @@ -0,0 +1,34 @@ +#include <stdio.h> +#include <stdlib.h> + +int greedy(int c[], int size) +{ + int k = 0, curr_sum = c[0]; + int types = 2, x; + for (x=1; x < size-1; x++) { + if (c[x] + curr_sum < c[x+1]) { + curr_sum += c[x]; + types++; + } + } + return types; +} + +int main() +{ + int tc; + scanf("%d", &tc); + + while (tc--) { + int n, c[1000], x; + scanf("%d", &n); + for (x=0; x<n; x++) { + int k; + scanf("%d", &k); + c[x] = k; + } + int types = greedy(c, n); + + printf("%d\n", types); + } +} |
