http://hihocoder.com/problemset/problem/1051
一开始dfs暴搜超时
这题关键在于理解到,肯定是补连续的几天。所以说写贪心之前要好好想想,怎么贪。
//补题卡肯定是连续使用的
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define INF 0x3f3f3f3f
#define MAXN 100010
const int MOD=1e9+;
typedef long long ll;
using namespace std;
int t, n, m, a[], memo[];
int k, maxm = -INF;
int main()
{
IO;
cin >> t;
while(t--){
maxm = -INF;
memset(memo, , sizeof(memo));
cin >> n >> m;
for(int i = ; i < n; i++){
cin >> a[i];
memo[a[i]] = ;
}
if(m >= n){
cout << "" << endl;
}
else {
for(int i = ; i < n-m+; i++){//起点
int j = i+m;//连续消掉的下一个
if(i == ){
maxm = max(maxm, a[j]-);
}
else if(j == n){
maxm = max(maxm, -a[i]);
}
else{
maxm = max(a[j]-a[i-]-, maxm);
}
}
cout << maxm << endl;
}
}
return ;
}