#include <bits/stdc++.h>
using namespace std;
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 = n - 1; i >= k - 1; i--)
{
while (a[i] != a[n - 1])
{
ans.push_back({2, i - k + 1});
for (int j = i - k + 1; j <= i; j++)
a[j]++;
}
}
for (int i = 0; i < k; i++)
{
while ((i != 0 && a[i] < a[i - 1]) || a[i] < a[n - 1])
{
ans.push_back({1, i});
a[i] += k;
}
}
for (int i = 0; i < n && k > 1; i++)
{
while ((i != 0 && a[i] < a[i - 1]) || a[i] < a[k - 2])
{
ans.push_back({1, i});
a[i] += k;
}
}
for (int i = 0; i < n % k; i++)
{
while (a[i] < a[n % k - 1])
{
ans.push_back({1, i});
a[i] += k;
}
}
for (int i = n % k; i < n && n % k; i += k)
{
while (a[i] < a[n % k - 1])
{
ans.push_back({2, i});
for (int j = i; j < i + k; j++)
a[j]++;
}
}
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... |