Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <math.h>
- #include <stdlib.h>
- #include <stack>
- #include <queue>
- #include <set>
- #include <map>
- #include <string>
- #include <algorithm>
- #include <iostream>
- using namespace std;
- int p, n, a[10010];
- bool can(int s0) {
- int i = 0, j, s;
- while (1) {
- s = 0;
- j = i;
- while (j < n && s < s0)
- s += a[j++];
- if (s != s0)
- return 0;
- if (j == n)
- return 1;
- i = j;
- }
- }
- int main() {
- //freopen("input.txt", "r", stdin);
- //freopen("output.txt", "w", stdout);
- scanf("%d", &p);
- for (int tst = 1; tst <= p; tst++) {
- scanf("%*d%d", &n);
- for (int i = 0; i < n; i++)
- scanf("%d", &a[i]);
- int s = 0, i = 0;
- do
- s += a[i++];
- while (!can(s));
- printf("%d %d\n", tst, s);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement