Advertisement
Guest User

Untitled

a guest
Sep 8th, 2013
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4. #include <stdlib.h>
  5. #include <stack>
  6. #include <queue>
  7. #include <set>
  8. #include <map>
  9. #include <string>
  10. #include <algorithm>
  11. #include <iostream>
  12. using namespace std;
  13.  
  14. int p, n, a[10010];
  15.  
  16. bool can(int s0) {
  17.     int i = 0, j, s;
  18.     while (1) {
  19.         s = 0;
  20.         j = i;
  21.         while (j < n && s < s0)
  22.             s += a[j++];
  23.         if (s != s0)
  24.             return 0;
  25.         if (j == n)
  26.             return 1;
  27.         i = j;
  28.     }  
  29. }
  30.  
  31. int main() {
  32.     //freopen("input.txt", "r", stdin);
  33.     //freopen("output.txt", "w", stdout);
  34.  
  35.     scanf("%d", &p);
  36.     for (int tst = 1; tst <= p; tst++) {
  37.         scanf("%*d%d", &n);
  38.         for (int i = 0; i < n; i++)
  39.             scanf("%d", &a[i]);
  40.         int s = 0, i = 0;
  41.         do
  42.             s += a[i++];
  43.         while (!can(s));
  44.         printf("%d %d\n", tst, s);
  45.     }
  46.    
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement