#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const double PI = acos(-1.0);
struct item {
int x, i, j;
};
vector < item > ans;
int n, k, mx, a[N];
ll sum;
int main() {
cin >> n >> k;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
sum += a[i];
mx = max(mx, a[i]);
}
if (sum % k != 0 || mx > sum / k) {
cout << -1;
return 0;
}
for (int i = 1; i <= n; ++i) {
if (!a[i])
continue;
for (int j = i + 1; j <= n; ++j) {
if (!a[i])
break;
if (!a[j])
continue;
ans.push_back({1, i, j});
--a[i];
--a[j];
}
}
cout << ans.size() << "\n";
for (auto it : ans) {
cout << it.x << " " << it.i << " " << it.j << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
476 KB |
n=3 |
3 |
Correct |
2 ms |
612 KB |
n=3 |
4 |
Incorrect |
2 ms |
612 KB |
Not all heaps are empty in the end |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
476 KB |
n=3 |
3 |
Correct |
2 ms |
612 KB |
n=3 |
4 |
Incorrect |
2 ms |
612 KB |
Not all heaps are empty in the end |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
476 KB |
n=3 |
3 |
Correct |
2 ms |
612 KB |
n=3 |
4 |
Incorrect |
2 ms |
612 KB |
Not all heaps are empty in the end |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
768 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Correct |
2 ms |
476 KB |
n=3 |
3 |
Correct |
2 ms |
612 KB |
n=3 |
4 |
Incorrect |
2 ms |
612 KB |
Not all heaps are empty in the end |
5 |
Halted |
0 ms |
0 KB |
- |