Under construction

Still being built. Things may change

Maximal Sum

Interview

Time limit1sMemory limit64 MB

Summary
Find the contiguous block of edge weights with the largest sum and print its endpoints, or print no good path when the best sum is not positive.
Level

Easy3 of 10

Topics
Dynamic programming, Array
Solved
No attempts yet

Problem

A graph has rr nodes in a line, numbered 1 to rr. The edge joining node ii and node i+1i+1 has weight wiw_i, and a weight can be positive or negative.

For i<ji < j, the value of the path from node ii to node jj is the sum of the weights the path crosses, wi+wi+1+⋯+wj−1w_i + w_{i+1} + \dots + w_{j-1}.

Write a program that finds the path with the largest value.

Input

The first line contains the number of test cases nn (1≤n≤1001 \le n \le 100).

Each test case starts with the number of nodes rr (2≤r≤502 \le r \le 50), followed by the integers w1,w2,…,wr−1w_1, w_2, \dots, w_{r-1}. Here wiw_i is the weight of the edge joining node ii and node i+1i+1, and −10000≤wi≤10000-10000 \le w_i \le 10000. Numbers are separated by whitespace or line breaks.

Output

For each test case, print on one line the starting node ii and the ending node jj of the path with the largest value, separated by a space.

If several paths reach the largest value, choose the longest one, the one whose j−ij-i is largest. If several paths share both the largest value and the same length, choose the one with the smallest ii.

If the largest value is not positive, print no good path.

Examples2

  1. Example 1

    Input
    4
    3 -1 6
    6 1 -2 1 6 -3
    10 4 -5 4 -3 4 4 -4 4 -5
    4 -2 -3 -4
    
    Expected output
    2 3
    3 5
    3 9
    no good path
    
  2. Example 2

    Input
    2
    2 5
    2 -5
    
    Expected output
    1 2
    no good path