This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using ld = long double;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const ll LINF = 2e18;
const double EPS = 1e-9;
#define EMT ios::sync_with_stdio(0); cin.tie(0);
signed main() { EMT
int n, k;
cin >> n >> k;
vector<int> arr(n);
priority_queue<pair<int, int>> pq;
for(int i = 0; i < n; i++)
cin >> arr[i], pq.push({arr[i], i});
vector<tuple<int, int, int>> ans;
auto get = [&]() {
if(pq.empty())
return -1;
int w = pq.top().second;
pq.pop();
return w;
};
while(!pq.empty()) {
int x = get(), y = get();
if(y < 0)
return cout << "-1\n", 0;
ans.push_back({1, x, y});
arr[x]--;
arr[y]--;
if(arr[x])
pq.push({arr[x], x});
if(arr[y])
pq.push({arr[y], y});
}
cout << ans.size() << '\n';
for(const auto &[v, x, y] : ans)
cout << v << ' ' << x + 1 << ' ' << y + 1 << '\n';
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |