C1. Pokémon Army (easy version):题目
题意:选择其中一部分,按照+-依此计算,求总和
思路:找到局部最大值,然后减去局部最小值,依此找。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> a((int)4e5);
vector<int> b((int)4e5);
string str;
int main()
{int t;cin>>t;while (t--){int n,q;cin>>n>>q;for (int i=0;i<n;i++){cin>>a[i];}ll res = 0;int ff = 1;for (int i = 0;i<n-1;i++){if (a[i]>a[i+1]) {if (ff) res+=a[i],ff = 0;}else if (!ff) res-=a[i],ff = 1;}if (ff) res+=a[n-1];cout<<res<<endl;}
}
今天是2022年2月26日,冲冲冲,今天写完这一页,写到1400