Super-increasing sequence

来源:互联网 发布:用友怎么初始化数据库 编辑:程序博客网 时间:2024/05/19 15:41


Description

如果一个序列中任意一项都大于前面所有项之和,那么我们就称这个序列为超递增序列。

现在有一个整数序列,你可以将序列中任意相邻的若干项合并成一项,合并之后这项的值为合并前各项的值之和。通过若干次合并,最终一定能得到一个超递增序列,那么得到的超递增序列最多能有多少项呢?

Input

输入数据的第一行包含正整数T (1 <= T <= 500),表示接下来一共有T组测试数据。

每组测试数据的第一行包含一个整数N (1 <= N <= 100000),表示这个整数序列一共有N项。接下来一行包含N个不大于10000的正整数,依次描述了这个序列中各项的值。

至多有10组数据满足N > 1000

Output

对于每组测试数据,用一行输出一个整数,表示最终得到的超递增序列最多能有多少项。

Sample Input

321 131 2 461 2 4 3 6 5

Sample Output

134

HINT

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <iterator>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#define MP make_pair
#define INF (1<<30)
#define PI acos(-1.0)
#define esp 1e-8
const int dx[4]={0,0,0,0};
using namespace std;
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)
#if defined (_WIN32) || defined (__WIN32) || defined (WIN32) || defined (__WIN32__)
#define LL __int64
#define LLS "%" "I" "6" "4" "d"
#else
#define LL long long
#define LLS "%" "l" "l" "d"
#endif


int main(int argc, char** argv) {
    //read;
    int t,n,x,sum,cnt,now_sum;
    scanf("%d",&t);
    while(t--) {
        scanf("%d%d",&n,&x);
        sum = x;
        now_sum = 0;
        cnt = 1;
        for(int i=1; i<n; i++) {
            scanf("%d",&x);
            now_sum += x;
            if(now_sum > sum) {
                sum = sum + now_sum;
                now_sum = 0;
                cnt ++;
            }
        }
        printf("%d\n",cnt);
    }
    return 0;
}

0 0