[Solution] Happy Subarrays Round G 2022 Solution - Kick Start 2022
Problem
Let us define as the sum of a subarray of an array bounded by indices and (both inclusive). Formally, .
An array of length is called a happy array if all the prefix sums of are non-negative. Formally, the terms are all non-negative.
Given an array of integers, find the result of adding the sums of all the happy subarrays in the array .
Input
The first line of the input gives the number of test cases, . test cases follow.
Each test case begins with one line consisting an integer denoting the number of integers in the input array . Then the next line contains integers representing the integers in given input array .
Output
For each test case, output one line containing Case #:
, where is the test case number (starting from 1) and is the result of adding the sums of all happy subarrays in the given input array .
Limits
Time limit: 25 seconds.
Memory limit: 1 GB.
.
, for all .
Test Set 1
.
Test Set 2
For at most 30 cases:
.
For the remaining cases:
.
No comments:
Post a Comment