Morass

PLANTS-SONGMAN

Sep 9th, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. using LINT = long long int;
  5. using PII = pair<int,int>;
  6.  
  7. #define PB push_back
  8. #define FI first
  9. #define SE second
  10. #define REP(i,n) for(int i=0;i<(n);++i)
  11. #define FOR(i, a, b) for(int i=(a);i<(b);++i)
  12.  
  13. int t;
  14. int n,k;
  15.  
  16. int arr[100007];
  17.  
  18. void process(){
  19.     cin>>n>>k;
  20.     REP(i,n)cin>>arr[i];
  21.  
  22.     multiset<int> pp;
  23.  
  24.     for(int i = 0; i < min(k+2,n); ++i)
  25.         pp.insert(arr[i]);
  26.     int best = 0;
  27.     REP(i,n){
  28.         best = max(best,*pp.rbegin()-arr[i]);
  29.         if(i+k+2<n)
  30.             pp.insert(arr[i+k+2]);
  31.         if(i-k-1>=0)
  32.             pp.erase(pp.find(arr[i-k-1]));
  33.     }
  34.     cout<<best<<endl;
  35. }
  36.  
  37. int main() {
  38.     cin>>t;
  39.     while(t--)process();
  40.     return 0;
  41. }
Add Comment
Please, Sign In to add comment