ACM:W: Super-increasing sequence

ACM:W: Super-increasing sequence

Description

如果一個序列中任意一項都大於前面所有項之和,那麼我們就稱這個序列爲超遞增序列。

現在有一個整數序列,你可以將序列中任意相鄰的若干項合併成一項,合併之後這項的值爲合併前各項的值之和。通過若干次合併,最終一定能得到一個超遞增序列,那麼得到的超遞增序列最多能有多少項呢?

Input

輸入數據的第一行包含正整數T (1 <= T <= 500),表示接下來一共有T組測試數據。

每組測試數據的第一行包含一個整數N (1 <= N <= 100000),表示這個整數序列一共有N項。接下來一行包含N個不大於10000的正整數,依次描述了這個序列中各項的值。

至多有10組數據滿足N > 1000

Output

對於每組測試數據,用一行輸出一個整數,表示最終得到的超遞增序列最多能有多少項。

Sample Input

3
2
1 1
3
1 2 4
6
1 2 4 3 6 5

Sample Output

1
3
4
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
#define N 100010
int aa[N];
int main()
{
    int T,n;
    cin>>T;
    while(T--)
    {
        cin>>n;
        for(int i=0;i<n;i++)
        {
            cin>>aa[i];
        }
        int sum=aa[0];
        int count=1;
        int now_sum=0;
        for(int i=1;i<n;i++)
        {
            now_sum +=aa[i];
            if(now_sum>sum)
            {
                sum +=now_sum;
                now_sum=0;
                count++;
            }
        }
        cout<<count<<endl;
    }
    return 0;
}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章