Gym 100947C——Rotate It !!(水题水题)

26 篇文章 0 订阅
8 篇文章 0 订阅
Rotate It !!
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

Dzy and Fox have a sequence A consisting of N numbers [A1...AN]. Dzy starts by taking the first number, then Fox takes the second number, then Dzy takes the third number and so on, they continue taking turns until all of the N numbers are taken. The player with the highest sum of numbers wins.

Since Dzy is your dear friend, you decided to rotate the sequence (you may rotate it as many times as you like) in order to maximize Dzy's sum of numbers.

Rotation is defined as removing the first element from the beginning of the sequence and adding it to the end of the sequence.

So given the sequence A , you have to help Dzy and let him achieve the maximum possible sum.

Input

The first line containts a single integer T, the number of test cases.

Then T testcases are given as follows :

The first line of each testcase contains a single integer N (1 ≤ n ≤ 104).

The second line of each testcase contains N space-separated integers [A1...AN],the elements of the sequence A (1 ≤ i ≤ n) ( - 109 ≤ Ai ≤ 109).

Output

Output T lines , The answer for each testcase which is the maximum achievable sum by Dzy if you help him.

Examples
input
1
5
1 5 3 2 4
output
12
Note

Consider all 5 rotations of the sequence:

1 5 3 2 4 (Dzy score = 1 + 3 + 4 = 8)

5 3 2 4 1 (Dzy score = 8)

3 2 4 1 5 (Dzy score = 12)

2 4 1 5 3 (Dzy score = 6)

4 1 5 3 2 (Dzy score = 11)


水题一道随便看看就当凑数。


#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <iostream>
using namespace std;

#define MAXN 10100
#define INF 10e9+7

long long a[MAXN];

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%I64d",a+i);
        }
        int x=n/2;
        if(n%2==1)
            x++;
        long long maxn=-10e15;
        for(int i=1;i<=n;i++)
        {
            int cnt=1;
            long long sum=a[i];
            int j=i;
            while(cnt<x)
            {
                if((j+2)==n+2)
                {
                    j=2;
                }
                else if((j+2)==n+1)
                {
                    j=1;
                }
                else
                {
                    j=j+2;
                }
                sum+=a[j];
                cnt++;
            }
            maxn=max(sum,maxn);
        }
        printf("%I64d\n",maxn);
    }
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值