-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathADAPLANT.cpp
91 lines (80 loc) · 1.7 KB
/
ADAPLANT.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
//#include <unordered_map>
#include <utility>
#include <cassert>
#include <iomanip>
#include <ctime>
#include <fstream>
using namespace std;
const int me = 300025;
template <class T> void FastInput(T &n){
char ch;
int sign = 1;
while(ch = getchar_unlocked(), isspace(ch)) {
};
n = 0;
if(ch == '-')
sign = -1;
else n = ch - '0';
while(ch = getchar_unlocked(), isdigit(ch))
n = (n << 3) + (n << 1) + ch - '0';
if(sign == -1)
n = ~n + 1;
}
template<class T> void FastPrint(T n){
if(n == 0){
puts("0");
return;
}
char buffer[256];
int ptr = 0, sign = 1;
if(n < 0){
sign = -1;
n = ~n + 1;
}
while(n > 0){
buffer[ptr ++] = (char)(n % 10 + '0');
n /= 10;
}
if(sign == -1)
putchar_unlocked('-');
for(int i = ptr - 1; i >= 0; i --)
putchar_unlocked(buffer[i]);
puts("");
}
int T, N, K;
int a[me];
int main() {
//ios_base::sync_with_stdio(0);
//cin.tie(0);
// testing fast I/O
FastInput(T);
while(T --){
FastInput(N);
FastInput(K);
multiset<int> s;
int ans = 0;
K += 2;
for(int i = 0; i < N; i ++){
FastInput(a[i]);
s.insert(a[i]);
if(i >= K)
s.erase(s.find(a[i - K]));
ans = max(ans, *(s.rbegin()) - *(s.begin()));
}
FastPrint(ans);
}
return 0;
}