아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Happy Subarrays

시간 제한25초메모리 제한1024 MB

요약
모든 접두사 합이 음수가 아닌 부분 배열들의 합을 모두 더한 값을 구한다.
난이도

보통10점 중 7점

유형
누적 합, 분할 정복, 정렬
정답자
아직 제출이 없습니다

문제

Let us define F(B,L,R)F(B, L, R) as the sum of a subarray of an array BB bounded by indices LL and RR (both inclusive). Formally, F(B,L,R)=B_L+B_L+1+⋯+B_RF(B, L, R) = B\_L + B\_{L+1} + \cdots + B\_R.

An array CC of length KK is called a happy array if all the prefix sums of CC are non-negative. Formally, the terms F(C,1,1),F(C,1,2),…,F(C,1,K)F(C, 1, 1), F(C, 1, 2), \dots, F(C, 1, K) are all non-negative.

Given an array A\mathbf{A} of N\mathbf{N} integers, find the result of adding the sums of all the happy subarrays in the array A\mathbf{A}.

입력

The first line of the input gives the number of test cases, T\mathbf{T}. T\mathbf{T} test cases follow.

Each test case begins with one line consisting an integer N\mathbf{N} denoting the number of integers in the input array A\mathbf{A}. Then the next line contains N\mathbf{N} integers A_1,A_2,…,A_N\mathbf{A\_1}, \mathbf{A\_2}, \dots, \mathbf{A\_N} representing the integers in given input array A\mathbf{A}.

출력

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is the result of adding the sums of all happy subarrays in the given input array A\mathbf{A}.

제한

  • 1≤T≤1001 \le \mathbf{T} \le 100.
  • −800≤A_i≤800-800 \le \mathbf{A\_i} \le 800, for all ii.

예제1

  1. 예제 1

    입력
    2
    5
    1 -2 3 -2 4
    3
    1 0 3
    
    예상 출력
    Case #1: 14
    Case #2: 12