제출 #1133246

#제출 시각아이디문제언어결과실행 시간메모리
1133246JelalTkmGift (IZhO18_nicegift)C++20
7 / 100
573 ms96472 KiB
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

using namespace std;

#define int long long int

const int N = 3e5 + 10;
const int md = 1e9 + 7;
const int INF = 1e18;

int32_t main(int32_t argc, char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int T = 1;
  // cin >> T;
  while (T--) {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
      cin >> a[i];

    if (k == 2) {
      set<pair<int, int>> s;
      for (int i = 0; i < n; i++)
        s.insert({a[i], i + 1});
      bool ok = 0;
      vector<pair<int, pair<int, int>>> ans;
      while (true) {
        auto it = s.end(), it1 = s.end();
        it--, it--, it1--;
        if (!((*it).first) xor !((*it1).first))
          break;
        if (!((*it).first) && !((*it1).first)) {
          ok = 1;
          break;
        }
        auto pr = *it, pr1 = *it1;
        int mn = min(pr.first, pr1.first);
        ans.push_back({mn, {pr.second, pr1.second}});
        s.erase(it), s.erase(it1);
        s.insert({pr.first - mn, pr.second});
        s.insert({pr1.first - mn, pr1.second});
      }
      if (ok) {
        cout << (int) ans.size() << '\n';
        for (auto i : ans)
          cout << i.first << " " << i.second.first << " " << i.second.second << '\n';
      } else {
        cout << -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...
#Verdict Execution timeMemoryGrader output
Fetching results...