Under construction

Still being built. Things may change

Exotic Foods

Interview

Time limit1sMemory limit128 MB

Summary
Given a sequence of food values, choose a subset with no two chosen positions adjacent so the total value is as large as possible.
Level

Medium4 of 10

Topics
Dynamic programming, Array, Greedy, Implementation
Solved
No attempts yet

Problem

Traveling through time is exhausting and quickly works up an appetite. Fortunately, every era is full of exotic foods such as dinosaur meat, dodo-bird eggs, and mammoth milk. Unfortunately, the time machine has no room for a refrigerator, so if Tim wants to eat an exotic food he must eat it on the spot. But once he eats, he becomes so full that he cannot eat anything at all during the very next era he visits. Each food has a value that Tim assigns to it, and his goal is to maximize the total value of the foods he actually eats. The order in which he visits the eras is already fixed and cannot be changed. By choosing which foods to eat, what is the maximum total value he can achieve?

Input

The first line contains the number KK of data sets. Then follow KK data sets, each in the following form. The first line of each data set contains an integer nn, the number of foods Tim will encounter, with 1≤n≤500001 \le n \le 50000. The next line contains nn integers viv_i giving the values of the foods, with 1≤vi≤10001 \le v_i \le 1000. The order of the viv_i is the order in which Tim encounters them.

Output

For each data set, first print Data Set x: on its own line, where xx is the data set's number starting from 1. On the next line, print the maximum total value Tim can achieve. Separate consecutive data sets with a single blank line.

Examples3

  1. Example 1

    Input
    2
    3
    3 8 4
    4
    12 8 9 10
    
    Expected output
    Data Set 1:
    8
    
    Data Set 2:
    22
    
  2. Example 2

    Input
    1
    1
    5
    
    Expected output
    Data Set 1:
    5
    
  3. Example 3

    Input
    3
    1
    7
    2
    5 5
    3
    1 2 3
    
    Expected output
    Data Set 1:
    7
    
    Data Set 2:
    5
    
    Data Set 3:
    4