#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
int n, k, h[50];
int main() {
cin >> n >> k;
for (int i = 0; i < n; ++i) cin >> h[i];
vector<pint> ans;
auto ver = [&] (int i) {
ans.emplace_back(1, i + 1);
h[i] += k;
};
auto hor = [&] (int i) {
ans.emplace_back(2, i + 1);
for (int j = i + k; --j >= i;) h[j]++;
};
for (int i = 1; i <= n - k; ++i) {
while ((h[i] - h[0]) % k) {
int mx = *max_element(h + i, h + i + k);
for (int j = i; j--;) {
while (h[j] <= mx) ver(j);
}
for (int j = n; --j >= i + k;) {
while (h[j] <= mx) ver(j);
}
hor(i);
}
}
int mx = *max_element(h, h + n);
for (int i = n; i--;) {
while (h[i] < mx) ver(i);
if (h[i] != mx) {
cout << -1;
return 0;
}
}
cout << ans.size() << endl;
for (auto [a, b]: ans) cout << a << " " << b << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |