-
Notifications
You must be signed in to change notification settings - Fork 2
/
c. IPL2021.cpp
51 lines (43 loc) · 1.06 KB
/
c. IPL2021.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
/*
Problem Link: https://practice.geeksforgeeks.org/problems/deee0e8cf9910e7219f663c18d6d640ea0b87f87/1/
Title: IPL 2021 - Match Day 2
Difficulty: Medium
Author: Hariket Sukesh Kumar Sheth
Language: C++
*/
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
vector<int> max_of_subarrays(vector<int> arr, int n, int k) {
vector<int>ans;
multiset<int>m;
for(int i=0;i<k;i++)
{
m.insert(arr[i]);
}
ans.push_back(*m.rbegin());
for(int i=k;i<arr.size();i++)
{
m.erase(m.find(arr[i-k]));
m.insert(arr[i]);
ans.push_back(*m.rbegin());
}
return ans;
}
};
int main() {
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
vector<int> arr(n);
for (int i = 0; i < n; i++) cin >> arr[i];
Solution ob;
vector<int> res = ob.max_of_subarrays(arr, n, k);
for (int i = 0; i < res.size(); i++) cout << res[i] << " ";
cout << endl;
}
return 0;
}