#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const int inf = 1e9;
void solve() {
int n, k;
cin >> n >> k;
vector<ll> a(n);
for (ll &x: a) cin >> x;
if (k == 2 and accumulate(a.begin(), a.end(), 0ll) <= 1e5) {
priority_queue<pair<ll, int>> pq;
for (int i = 0; i < n; i++) pq.emplace(a[i], i);
vector<pair<int, int>> ans;
while (pq.size() > 1) {
auto it1 = pq.top(); pq.pop();
auto it2 = pq.top(); pq.pop();
ans.emplace_back(it1.second + 1, it2.second + 1);
it1.first--; it2.first--;
if (it1.first > 0) pq.emplace(it1);
if (it2.first > 0) pq.emplace(it2);
}
if (!pq.empty()) {
cout << -1;
return;
}
cout << ans.size() << '\n';
for (auto [i, j]: ans) cout << "1 " << i << ' ' << j << '\n';
return;
}
}
int main() {
cin.tie(0)->sync_with_stdio(false);
#ifdef sunnatov
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int queries = 1;
// cin >> queries;
for (int test_case = 1; test_case <= queries; test_case++) {
#ifdef sunnatov
cout << "Test case: " << test_case << endl;
#endif
solve();
cout << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n=4 |
2 |
Correct |
1 ms |
348 KB |
n=3 |
3 |
Correct |
1 ms |
348 KB |
n=3 |
4 |
Correct |
1 ms |
348 KB |
n=4 |
5 |
Correct |
1 ms |
348 KB |
n=4 |
6 |
Correct |
0 ms |
348 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n=4 |
2 |
Correct |
1 ms |
348 KB |
n=3 |
3 |
Correct |
1 ms |
348 KB |
n=3 |
4 |
Correct |
1 ms |
348 KB |
n=4 |
5 |
Correct |
1 ms |
348 KB |
n=4 |
6 |
Correct |
0 ms |
348 KB |
n=2 |
7 |
Correct |
1 ms |
348 KB |
n=5 |
8 |
Correct |
1 ms |
604 KB |
n=8 |
9 |
Correct |
5 ms |
604 KB |
n=14 |
10 |
Correct |
2 ms |
604 KB |
n=11 |
11 |
Correct |
17 ms |
3288 KB |
n=50000 |
12 |
Correct |
17 ms |
3272 KB |
n=50000 |
13 |
Correct |
8 ms |
1244 KB |
n=10 |
14 |
Correct |
16 ms |
1248 KB |
n=685 |
15 |
Correct |
13 ms |
1248 KB |
n=623 |
16 |
Correct |
8 ms |
1148 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n=4 |
2 |
Correct |
1 ms |
348 KB |
n=3 |
3 |
Correct |
1 ms |
348 KB |
n=3 |
4 |
Correct |
1 ms |
348 KB |
n=4 |
5 |
Correct |
1 ms |
348 KB |
n=4 |
6 |
Correct |
0 ms |
348 KB |
n=2 |
7 |
Correct |
1 ms |
348 KB |
n=5 |
8 |
Correct |
1 ms |
604 KB |
n=8 |
9 |
Correct |
5 ms |
604 KB |
n=14 |
10 |
Correct |
2 ms |
604 KB |
n=11 |
11 |
Correct |
17 ms |
3288 KB |
n=50000 |
12 |
Correct |
17 ms |
3272 KB |
n=50000 |
13 |
Correct |
8 ms |
1244 KB |
n=10 |
14 |
Correct |
16 ms |
1248 KB |
n=685 |
15 |
Correct |
13 ms |
1248 KB |
n=623 |
16 |
Correct |
8 ms |
1148 KB |
n=973 |
17 |
Incorrect |
1 ms |
348 KB |
Unexpected end of file - int32 expected |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
124 ms |
15012 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n=4 |
2 |
Correct |
1 ms |
348 KB |
n=3 |
3 |
Correct |
1 ms |
348 KB |
n=3 |
4 |
Correct |
1 ms |
348 KB |
n=4 |
5 |
Correct |
1 ms |
348 KB |
n=4 |
6 |
Correct |
0 ms |
348 KB |
n=2 |
7 |
Correct |
1 ms |
348 KB |
n=5 |
8 |
Correct |
1 ms |
604 KB |
n=8 |
9 |
Correct |
5 ms |
604 KB |
n=14 |
10 |
Correct |
2 ms |
604 KB |
n=11 |
11 |
Correct |
17 ms |
3288 KB |
n=50000 |
12 |
Correct |
17 ms |
3272 KB |
n=50000 |
13 |
Correct |
8 ms |
1244 KB |
n=10 |
14 |
Correct |
16 ms |
1248 KB |
n=685 |
15 |
Correct |
13 ms |
1248 KB |
n=623 |
16 |
Correct |
8 ms |
1148 KB |
n=973 |
17 |
Incorrect |
1 ms |
348 KB |
Unexpected end of file - int32 expected |
18 |
Halted |
0 ms |
0 KB |
- |