#include<bits/stdc++.h>
using namespace std;
int main(){
int n, k;
cin >> n >> k;
priority_queue <pair <int, int>> pq;
for(int i = 0;i < n;i++){
int x;
cin >> x;
pq.push({x, i});
}
vector <array <int, 3>> resp;
while(!pq.empty()){
if(pq.size() == 1){
cout << -1 << '\n';
return 0;
}
auto [val, pos] = pq.top();
pq.pop();
auto [val2, pos2] = pq.top();
pq.pop();
val -= val2;
resp.push_back({val2, pos, pos2});
if(val != 0) pq.push({val, pos});
}
cout << resp.size()<< '\n';
for(auto x : resp){
cout << x[0] << ' ' << x[1]+1 << ' ' << x[2]+1 << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n=4 |
2 |
Correct |
0 ms |
348 KB |
n=3 |
3 |
Correct |
0 ms |
348 KB |
n=3 |
4 |
Correct |
0 ms |
344 KB |
n=4 |
5 |
Correct |
0 ms |
348 KB |
n=4 |
6 |
Correct |
0 ms |
348 KB |
n=2 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n=4 |
2 |
Correct |
0 ms |
348 KB |
n=3 |
3 |
Correct |
0 ms |
348 KB |
n=3 |
4 |
Correct |
0 ms |
344 KB |
n=4 |
5 |
Correct |
0 ms |
348 KB |
n=4 |
6 |
Correct |
0 ms |
348 KB |
n=2 |
7 |
Correct |
1 ms |
344 KB |
n=5 |
8 |
Correct |
0 ms |
344 KB |
n=8 |
9 |
Incorrect |
0 ms |
348 KB |
Jury has the answer but participant has not |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n=4 |
2 |
Correct |
0 ms |
348 KB |
n=3 |
3 |
Correct |
0 ms |
348 KB |
n=3 |
4 |
Correct |
0 ms |
344 KB |
n=4 |
5 |
Correct |
0 ms |
348 KB |
n=4 |
6 |
Correct |
0 ms |
348 KB |
n=2 |
7 |
Correct |
1 ms |
344 KB |
n=5 |
8 |
Correct |
0 ms |
344 KB |
n=8 |
9 |
Incorrect |
0 ms |
348 KB |
Jury has the answer but participant has not |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
212 ms |
32984 KB |
Not all heaps are empty in the end |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n=4 |
2 |
Correct |
0 ms |
348 KB |
n=3 |
3 |
Correct |
0 ms |
348 KB |
n=3 |
4 |
Correct |
0 ms |
344 KB |
n=4 |
5 |
Correct |
0 ms |
348 KB |
n=4 |
6 |
Correct |
0 ms |
348 KB |
n=2 |
7 |
Correct |
1 ms |
344 KB |
n=5 |
8 |
Correct |
0 ms |
344 KB |
n=8 |
9 |
Incorrect |
0 ms |
348 KB |
Jury has the answer but participant has not |
10 |
Halted |
0 ms |
0 KB |
- |