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