#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
using namespace std;
const long long oo = 1000000000000000000;
long long int sum, ans = 0, mx = 0, mn = 1000000000, num, pos;
/*
ViHHiPuh
(( `'-""``""-'` ))
)-__-_.._-__-(
/ --- (o _ o) --- \
\ .-* ( .0. ) *-. /
_'-. ,_ '=' _, .-'_
/ `;#'#'# - #'#'#;` \
\_)) -----'#'----- ((_/
# --------- #
'# ------- ------ #'
/..-'# ------- #'-.\
_\...-\'# -- #'/-.../_
((____)- '#' -(____))
cout << fixed << setprecision(6) << x;
freopen ( "sum.in", "r", stdin )
*/
set <pair<int, int> > st;
vector <pair<int, pair<int, int> > > vv;
int main () {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m;
int a[ n + 1 ];
for ( int i = 1; i <= n; i ++ ) {
cin >> a[ i ];
}
if( m == 2 ) {
for ( int i = 1; i <= n; i ++ ) {
sum += a[ i ];
st.insert( { a[ i ], i } );
}
if ( sum % 2 ) {
cout << "-1";
return 0;
}
pair<int, int> p1, p2, p3;
while ( st.size() > 2 ) {
p1 = *( --st.end() );
st.erase( --st.end() );
p2 = *( --st.end() );
st.erase( --st.end() );
p3 = *( --st.end() );
st.erase( --st.end() );
num = p2.first - p3.first + 1;
vv.push_back( { num, make_pair( p1.second, p2.second ) } );
p2.first -= num;
p1.first -= num;
if ( p1.first > 0 )
st.insert( p1 );
if ( p2.first > 0 )
st.insert( p2 );
st.insert( p3 );
}
if ( st.size() == 2 )
vv.push_back( { st.begin()->first, make_pair(st.begin()->second, ( ++st.begin() )->second ) } );
cout << vv.size() << "\n";
for ( auto i : vv )
cout << i.first << " " << i.second.first << " " << i.second.second << "\n";
}
}
/*
7 2
14 12 12 6 4 20 18
5
18 7 6
2 1 6
12 3 1
6 4 2
4 5 2
20 18 14 12 12 6 4
14 13 13 12 12 6 4
13 13 12 12 12 6 4
12 12 12 12 12 6 4
12 12 12 11 11 6 4
12 11 11 11 11 6 4
11 11 11 11 10 6 4
11 11 10 10 10 6 4
10 10 10 10 10 6 4
8 8 8 8 8 6 4
6 6 6 6 6 6 4
14 12 12 6 4 2 0
12 12 12 6 4 0 0
0 12 0 6 4 0 0
0 6 0 0 4 0 0
0 2 0 0 0 0 0
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
n=4 |
2 |
Correct |
1 ms |
204 KB |
n=3 |
3 |
Correct |
0 ms |
312 KB |
n=3 |
4 |
Correct |
1 ms |
312 KB |
n=4 |
5 |
Correct |
0 ms |
332 KB |
n=4 |
6 |
Correct |
1 ms |
308 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
n=4 |
2 |
Correct |
1 ms |
204 KB |
n=3 |
3 |
Correct |
0 ms |
312 KB |
n=3 |
4 |
Correct |
1 ms |
312 KB |
n=4 |
5 |
Correct |
0 ms |
332 KB |
n=4 |
6 |
Correct |
1 ms |
308 KB |
n=2 |
7 |
Correct |
1 ms |
204 KB |
n=5 |
8 |
Incorrect |
1 ms |
332 KB |
Not all heaps are empty in the end |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
n=4 |
2 |
Correct |
1 ms |
204 KB |
n=3 |
3 |
Correct |
0 ms |
312 KB |
n=3 |
4 |
Correct |
1 ms |
312 KB |
n=4 |
5 |
Correct |
0 ms |
332 KB |
n=4 |
6 |
Correct |
1 ms |
308 KB |
n=2 |
7 |
Correct |
1 ms |
204 KB |
n=5 |
8 |
Incorrect |
1 ms |
332 KB |
Not all heaps are empty in the end |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
251 ms |
51128 KB |
Jury has the answer but participant has not |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
n=4 |
2 |
Correct |
1 ms |
204 KB |
n=3 |
3 |
Correct |
0 ms |
312 KB |
n=3 |
4 |
Correct |
1 ms |
312 KB |
n=4 |
5 |
Correct |
0 ms |
332 KB |
n=4 |
6 |
Correct |
1 ms |
308 KB |
n=2 |
7 |
Correct |
1 ms |
204 KB |
n=5 |
8 |
Incorrect |
1 ms |
332 KB |
Not all heaps are empty in the end |
9 |
Halted |
0 ms |
0 KB |
- |