Submission #1054377

#TimeUsernameProblemLanguageResultExecution timeMemory
1054377juicyJOIRIS (JOI16_joiris)C++17
100 / 100
1 ms460 KiB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  int n, k; cin >> n >> k;
  vector<int> a(n), b(k), cnt(k);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    b[i % k] = (b[i % k] + a[i]) % k;
  } 
  for (int i = 1; i < n % k; ++i) {
    if (b[i] != b[i - 1]) {
      cout << -1;
      exit(0);
    }
  }
  for (int i = n % k + 1; i < k; ++i) {
    if (b[i] != b[i - 1]) {
      cout << -1;
      exit(0);
    }
  }
  vector<array<int, 2>> res;
  for (int i = 1; i < n; ++i) {
    while (a[i] < a[i - 1]) {
      a[i] += k;
      res.push_back({1, i});
    } 
  }
  for (int i = 1; i < n; ++i) {
    int dif = a[i] - a[i - 1];
    while (dif--) {
      for (int j = i - k; j >= 0; j -= k) {
        res.push_back({2, j});
      }
      for (int j = 0; j < i % k; ++j) {
        ++cnt[j];
      }
    }
  }
  for (int i = 0; i < k - 1; ++i) {
    while (cnt[i] > 0) {
      res.push_back({1, i});
      cnt[i] -= k;
    }
  }
  int rem = -cnt[0];
  while (rem--) {
    for (int j = n % k; j < n; j += k) {
      res.push_back({2, j});
    }
  }
  cout << res.size() << "\n";
  for (auto [t, x] : res) {
    cout << t << " " << x + 1 << "\n";
  }
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...