Skip to content

Instantly share code, notes, and snippets.

@Biazus
Created January 21, 2017 01:02
Show Gist options
  • Save Biazus/b992cf1171f5cc8f48c70ad2dbf4f8d6 to your computer and use it in GitHub Desktop.
Save Biazus/b992cf1171f5cc8f48c70ad2dbf4f8d6 to your computer and use it in GitHub Desktop.
Deque-STL Solution (without deque) - https://www.hackerrank.com/challenges/deque-stl
#include <iostream>
#include <algorithm> // std::sort
#include <map>
using namespace std;
void printKMax(int arr[], int n, int k){
vector<pair<int,int> > d;
for(int i=0; i<n;i++){
d.push_back(make_pair(arr[i],i));
}
sort(d.rbegin(),d.rend());
for(int i=0; i<n-k+1;i++){
for(int j=0;j<n;j++){
if(d[j].second >=i && d[j].second < (i+k)){
cout << d[j].first << ' ';
break;
}
}
}
}
int main(){
int t;
cin >> t;
while(t>0) {
int n,k;
cin >> n >> k;
int i;
int arr[n];
for(i=0;i<n;i++)
cin >> arr[i];
printKMax(arr, n, k);
t--;
if(t>0){
endl(cout);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment