#include <bits/stdc++.h>
#define pb push_back
#define sz(v) (int)v.size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define x first
#define y second
#define int long long
#define nl "\n"
using namespace std;
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair <ll, ll> pii;
const int N = (int)3e5 + 7;
const int M = (int)7e6 + 7;
const ll MOD = (ll)1e9 + 7;
const int inf = (int)1e9 + 7;
const ll INF = (ll)3e18 + 7;
pii dir[] = {{-1, -1}, {1, 1}, {-1, 1}, {1, -1}};
int n, k;
pii a[N];
void solve() {
cin >> n >> k;
int sum = 0;
for(int i = 1; i <= n; ++i) {
cin >> a[i].x;
a[i].y = i;
sum += a[i].x;
}
sort(a + 1, a + 1 + n);
if(sum % k || a[n].x > sum - a[n].x) cout << "-1\n", exit(0);
cout << sum / 2 << nl;
for(int i = 1; i <= sum / 2; ++i) {
cout << "1 " << a[n].y << ' ' << a[n-1].y << nl;
a[n].x--;
a[n-1].x--;
sort(a + 1, a + 1 + n);
}
}
signed main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0);
cout.tie(0);
int test = 1;
//cin >> test;
for(int i = 1; i <= test; ++i) {
//cout << "Case " << i << ": ";
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
n=4 |
2 |
Correct |
0 ms |
204 KB |
n=3 |
3 |
Correct |
0 ms |
204 KB |
n=3 |
4 |
Correct |
0 ms |
316 KB |
n=4 |
5 |
Correct |
0 ms |
204 KB |
n=4 |
6 |
Correct |
0 ms |
204 KB |
n=2 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
n=4 |
2 |
Correct |
0 ms |
204 KB |
n=3 |
3 |
Correct |
0 ms |
204 KB |
n=3 |
4 |
Correct |
0 ms |
316 KB |
n=4 |
5 |
Correct |
0 ms |
204 KB |
n=4 |
6 |
Correct |
0 ms |
204 KB |
n=2 |
7 |
Correct |
0 ms |
204 KB |
n=5 |
8 |
Correct |
0 ms |
204 KB |
n=8 |
9 |
Correct |
4 ms |
332 KB |
n=14 |
10 |
Correct |
3 ms |
332 KB |
n=11 |
11 |
Execution timed out |
2058 ms |
1224 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
n=4 |
2 |
Correct |
0 ms |
204 KB |
n=3 |
3 |
Correct |
0 ms |
204 KB |
n=3 |
4 |
Correct |
0 ms |
316 KB |
n=4 |
5 |
Correct |
0 ms |
204 KB |
n=4 |
6 |
Correct |
0 ms |
204 KB |
n=2 |
7 |
Correct |
0 ms |
204 KB |
n=5 |
8 |
Correct |
0 ms |
204 KB |
n=8 |
9 |
Correct |
4 ms |
332 KB |
n=14 |
10 |
Correct |
3 ms |
332 KB |
n=11 |
11 |
Execution timed out |
2058 ms |
1224 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2094 ms |
4996 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
n=4 |
2 |
Correct |
0 ms |
204 KB |
n=3 |
3 |
Correct |
0 ms |
204 KB |
n=3 |
4 |
Correct |
0 ms |
316 KB |
n=4 |
5 |
Correct |
0 ms |
204 KB |
n=4 |
6 |
Correct |
0 ms |
204 KB |
n=2 |
7 |
Correct |
0 ms |
204 KB |
n=5 |
8 |
Correct |
0 ms |
204 KB |
n=8 |
9 |
Correct |
4 ms |
332 KB |
n=14 |
10 |
Correct |
3 ms |
332 KB |
n=11 |
11 |
Execution timed out |
2058 ms |
1224 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |