#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
#include <ctime>
#include <map>
typedef long long llong;
const int MAXN = 100000 + 10;
const int INF = 1e9;
int n, k;
int a[MAXN];
int cnt[MAXN];
std::vector <std::pair <int,int>> ops;
void solve()
{
int sum = 0;
for (int i = 1 ; i <= n ; ++i)
{
sum += a[i];
}
sum %= n;
bool isOk = false;
for (int i = 1 ; i <= n ; ++i)
{
if ((k * i + sum) % n == 0)
{
isOk = true;
break;
}
}
if (!isOk)
{
std::cout << -1 << '\n';
return;
}
int max = 0;
for (int i = 1 ; i <= n ; ++i)
{
max = std::max(max, a[i]);
}
for (int i = 1 ; i <= n ; ++i)
{
while (a[i] < max)
{
a[i] += k;
ops.push_back({1, i});
}
}
for (int i = 1 ; i <= n ; ++i)
{
a[i] -= max;
}
// k = 2 from now on
for (int i = 1 ; i + 1 <= n ; ++i)
{
if (a[i] == 0 && a[i + 1] == 0)
{
ops.push_back({2, i});
a[i]++; a[i + 1]++;
i++;
}
}
for (int i = 1 ; i <= n ; i += 2)
{
if (a[i] == 0)
{
ops.push_back({1, i});
for (int j = 1 ; j < i ; j += 2)
{
ops.push_back({2, j});
}
for (int j = i + 1 ; j < n ; j += 2)
{
ops.push_back({2, j});
}
a[i]++;
}
}
for (int i = 2 ; i <= n ; i += 2)
{
if (a[i] == 0)
{
ops.push_back({1, i});
a[i] += 2;
}
}
for (int i = 1 ; i <= n ; ++i)
{
a[i]--;
}
for (int i = 1 ; i + 1 <= n ; ++i)
{
if (a[i] == 0 && a[i + 1] == 0)
{
ops.push_back({2, i});
a[i]++; a[i + 1]++;
i++;
}
}
for (int i = 1 ; i <= n ; i += 2)
{
if (a[i] == 0)
{
ops.push_back({1, i});
for (int j = 1 ; j < i ; j += 2)
{
ops.push_back({2, j});
}
for (int j = i + 1 ; j < n ; j += 2)
{
ops.push_back({2, j});
}
a[i]++;
}
}
// std::cerr << "at the end\n";
// for (int i = 1 ; i <= n ; ++i)
// {
// std::cout << a[i] << ' ';
// }
// std::cout << '\n';
}
void input()
{
std::cin >> n >> k;
for (int i = 1 ; i <= n ; ++i)
{
std::cin >> a[i];
}
}
void print()
{
std::cout << ops.size() << '\n';
for (const auto &[x, y] : ops)
{
std::cout << x << ' ' << y << '\n';
}
}
void fastIOI()
{
std::ios_base :: sync_with_stdio(0);
std::cout.tie(nullptr);
std::cin.tie(nullptr);
}
int main()
{
fastIOI();
input();
solve();
print();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Extra information in the output file |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
412 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Extra information in the output file |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Extra information in the output file |
2 |
Halted |
0 ms |
0 KB |
- |