#include <bits/stdc++.h>
using namespace std;
#define int short int
typedef pair <int, int> pii;
const int MAXN = 5e1 + 10;
int a[MAXN];
int s[MAXN];
vector <pii> ans;
void query(int type, int ind, int k)
{
if (type == 1)
{
a[ind] += k;
}
else
{
for (int i = ind; i < ind + k; i++)
a[ind]++;
}
ans.push_back({type, ind});
}
signed main()
{
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
s[(i - 1) % k] = (s[(i - 1) % k] + a[i]) % k;
}
for (int i = 0; i < n % k; i++)
{
if (s[i] != s[0])
{
cout << -1 << endl;
return 0;
}
}
for (int i = n % k; i < k; i++)
{
if (s[i] != s[n % k])
{
cout << -1 << endl;
return 0;
}
}
for (int i = 2; i <= n; i++)
{
while (a[i] < a[i - 1])
query(1, i, k);
}
for (int i = k + 1; i <= n; i++)
{
while (a[i - 1] < a[i])
{
for (int j = (i - 1) & k + 1; j < i; j += k)
query(2, j, k);
}
}
for (int i = 1; i < k; i++)
{
while (a[i] < a[n])
query(1, i, k);
}
int mx = 0;
for (int i = n % k + 1; i <= k; i++)
mx = max(mx, a[i]);
for (int i = 1; i <= n; i++)
{
while (a[i] < mx)
query(1, i, k);
}
mx = 0;
for (int i = 1; i <= n % k; i++)
mx = max(mx, a[i]);
for (int i = 1; i <= n % k; i++)
{
while (a[i] < mx)
query(1, i, k);
}
for (int i = n % k + 1; i <= n; i += k)
{
while (a[i] < mx)
query(2, i, k);
}
cout << ans.size() << '\n';
for (auto [x, y] : ans)
cout << x << " " << y << '\n';
return 0;
}
# | 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... |