#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;
signed main()
{
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++)
{
cin >> a[i];
s[i % k] = (s[i % 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 = 1; i < n; i++)
{
while (a[i] < a[i - 1])
{
ans.push_back({1, i});
a[i] += k;
}
}
for (int i = k; i < n; i++)
{
while (a[i - 1] != a[i])
{
for (int j = i; j >= k - 1; j -= k)
{
ans.push_back({2, j - k + 1});
for (int x = j - k + 1; x <= j; x++)
a[x]++;
}
}
}
for (int i = 0; i < k - 1; i++)
{
while (a[i] < a[n - 1])
{
ans.push_back({1, i});
a[i] += k;
}
}
int mx = 0;
for (int i = n % k; i < k - 1; i++)
mx = max(mx, a[i]);
for (int i = 0; i < n; i++)
{
while (a[i] < mx)
{
ans.push_back({1, i});
a[i] += k;
}
}
mx = 0;
for (int i = 0; i < n % k; i++)
mx = max(mx, a[i]);
for (int i = 0; i < n % k; i++)
{
while (a[i] < mx)
{
ans.push_back({1, i});
a[i] += k;
}
}
for (int i = n % k; i < n; i += k)
{
while (a[i] < mx)
{
ans.push_back({2, i});
for (int j = i; j < i + k; j++)
a[j]++;
}
}
cout << ans.size() << endl;
for (auto [x, y] : ans)
cout << x << " " << y + 1 << 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... |