#include <iostream>
#include <deque>
using namespace std;
void printKMax(int arr[], int n, int k) {
deque<int>dq;
int i;
for (i = 0; i < k; i++) {
while (dq.back() < arr[i]) {
dq.pop_back();
dq.push_back(i);
}
}
for (; i < n; i++) {
cout << dq.front();
while (dq.front() <= i - k) {
dq.pop_front();
}
while (dq.back() < arr[i]) {
dq.pop_back();
dq.push_back(i);
}
}
cout << dq.front();
}
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--;
}
return 0;
}
I don't know where I did wrong in program that caused the following errors appear:
- This error appears when program run to this code in arr[n]
expression must have a constant value the value of variable cannot be used as a constant
expression did not evaluate to a constant
If someone knows how to solve above errors, please help me.
Thanks you so much.