C1. Pokémon Army (easy version)

C1. Pokémon Army (easy version)

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

This is the easy version of the problem. The difference between the versions is that the easy version has no swap operations. You can make hacks only if all versions of the problem are solved.

Pikachu is a cute and friendly pokémon living in the wild pikachu herd.

But it has become known recently that infamous team R wanted to steal all these pokémon! Pokémon trainer Andrew decided to help Pikachu to build a pokémon army to resist.

First, Andrew counted all the pokémon — there were exactly nn pikachu. The strength of the ii-th pokémon is equal to aiai, and all these numbers are distinct.

As an army, Andrew can choose any non-empty subsequence of pokemons. In other words, Andrew chooses some array bb from kk indices such that 1≤b1<b2<⋯<bk≤n1≤b1<b2<⋯<bk≤n, and his army will consist of pokémons with forces ab1,ab2,…,abkab1,ab2,…,abk.

The strength of the army is equal to the alternating sum of elements of the subsequence; that is, ab1−ab2+ab3−ab4+…ab1−ab2+ab3−ab4+….

Andrew is experimenting with pokémon order. He performs qq operations. In ii-th operation Andrew swaps lili-th and riri-th pokémon.

Note: q=0q=0 in this version of the task.

Andrew wants to know the maximal stregth of the army he can achieve with the initial pokémon placement. He also needs to know the maximal strength after each operation.

Help Andrew and the pokémon, or team R will realize their tricky plan!

Input

Each test contains multiple test cases.

The first line contains one positive integer tt (1≤t≤1031≤t≤103) denoting the number of test cases. Description of the test cases follows.

The first line of each test case contains two integers nn and qq (1≤n≤3⋅105,q=01≤n≤3⋅105,q=0) denoting the number of pokémon and number of operations respectively.

The second line contains nn distinct positive integers a1,a2,…,ana1,a2,…,an (1≤ai≤n1≤ai≤n) denoting the strengths of the pokémon.

ii-th of the last qq lines contains two positive integers lili and riri (1≤li≤ri≤n1≤li≤ri≤n) denoting the indices of pokémon that were swapped in the ii-th operation.

It is guaranteed that the sum of nn over all test cases does not exceed 3⋅1053⋅105, and the sum of qq over all test cases does not exceed 3⋅1053⋅105.

Output

For each test case, print q+1q+1 integers: the maximal strength of army before the swaps and after each swap.

Example

input

Copy

3
3 0
1 3 2
2 0
1 2
7 0
1 2 5 4 3 6 7

output

Copy

3
2
9

Note

In third test case we can build an army in such way: [1 2 5 4 3 6 7], its strength will be 5−3+7=95−3+7=9.

=========================================================================

比较好玩的贪心,我们加的时候找递增的末尾,减的时候找递减的末尾即可

#include<iostream>
# include<algorithm>
# include<unordered_map>

using namespace std;
typedef long long int  ll;
int a[300000+10];
int main ()
{

    int t;
    cin>>t;

    while(t--)
    {
        int n;
        cin>>n;
        int p;
        cin>>p;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        int now=1;
        ll ans=0;
        int temp;
        for(int i=1;i<n;i++)
        {
            if(now==1)
            {
                if(a[i]<a[i+1])
                {
                    temp=a[i+1];
                }
                else
                {
                    temp=a[i];
                    ans+=temp;
                    now=0;
                }
            }
            else if(now==0)
            {
                if(a[i]>a[i+1])
                {
                    temp=a[i+1];

                }
                else
                {
                    temp=a[i];
                    ans-=temp;
                    now=1;
                }
            }

        }

        if(now==1)
        {
            ans+=a[n];
        }

        cout<<ans<<endl;
    }

    return 0;

}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
Pokémon Go开源项目是指将该游戏的源代码公开发布,供开发者和游戏爱好者免费使用和修改。这样一来,任何人都可以查看、学习、改进和共享该项目的代码。 将Pokémon Go开源的好处之一是促进了开源社区的发展。开源项目通常会吸引大量的开发者参与其中,他们可以为项目提供新的功能、修复错误和改进性能等贡献,从而提升游戏的质量和稳定性。这种合作模式可以促进技术的快速进步和创新,为用户带来更好的游戏体验。 另外,开源项目可以促进知识共享和学习。任何人都可以自由地查看和学习Pokémon Go的源代码,了解其中的技术实现和设计思路。对于新手开发者来说,这是一个非常好的学习资源,他们可以从中获取经验和灵感,提升自己的编程能力。 除此之外,开源项目还有利于游戏的改进和适应,特别是在特定地区或用户群体需求的情况下。开源代码使得游戏的定制化更加容易,可以针对特定的需求进行修改和适配,比如在某个国家或地区添加特定的功能或元素,或者根据用户的反馈进行改进和优化,从而更好地满足用户的需求。 总的来说,Pokémon Go开源项目的推出将会带来多方面的好处,包括促进开源社区的壮大、知识共享和学习的机会,以及游戏改进和适应的灵活性等。这对于开发者和玩家来说都是一个积极的举措。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qinsanma and Code

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值