#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;
}
if(pq.size() == 2){
auto [a1, p1] = pq.top();
pq.pop();
auto [a2, p2] = pq.top();
pq.pop();
if(a1 != a2){
cout << -1 << '\n';
return 0;
}
resp.push_back({a1, p1, p2});
break;
}
if(pq.size() == 3){
auto [a1, p1] = pq.top();
pq.pop();
auto[a2, p2] = pq.top();
pq.pop();
auto [a3, p3] = pq.top();
pq.pop();
if(!(a1 != a2 or a1 != a3)){
if(a1 % 2 != 0){
cout << "-1\n";
return 0;
}
resp.push_back({a1/2, p1, p2});
resp.push_back({a1/2, p1, p3});
resp.push_back({a1/2, p2, p3});
break;
}
pq.push({a1, p1});
pq.push({a2, p2});
pq.push({a3, p3});
}
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 |
348 KB |
n=4 |
2 |
Correct |
0 ms |
348 KB |
n=3 |
3 |
Correct |
0 ms |
348 KB |
n=3 |
4 |
Correct |
0 ms |
348 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 |
348 KB |
n=4 |
2 |
Correct |
0 ms |
348 KB |
n=3 |
3 |
Correct |
0 ms |
348 KB |
n=3 |
4 |
Correct |
0 ms |
348 KB |
n=4 |
5 |
Correct |
0 ms |
348 KB |
n=4 |
6 |
Correct |
0 ms |
348 KB |
n=2 |
7 |
Correct |
0 ms |
348 KB |
n=5 |
8 |
Correct |
0 ms |
348 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 |
348 KB |
n=4 |
2 |
Correct |
0 ms |
348 KB |
n=3 |
3 |
Correct |
0 ms |
348 KB |
n=3 |
4 |
Correct |
0 ms |
348 KB |
n=4 |
5 |
Correct |
0 ms |
348 KB |
n=4 |
6 |
Correct |
0 ms |
348 KB |
n=2 |
7 |
Correct |
0 ms |
348 KB |
n=5 |
8 |
Correct |
0 ms |
348 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 |
206 ms |
32684 KB |
Not all heaps are empty in the end |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n=4 |
2 |
Correct |
0 ms |
348 KB |
n=3 |
3 |
Correct |
0 ms |
348 KB |
n=3 |
4 |
Correct |
0 ms |
348 KB |
n=4 |
5 |
Correct |
0 ms |
348 KB |
n=4 |
6 |
Correct |
0 ms |
348 KB |
n=2 |
7 |
Correct |
0 ms |
348 KB |
n=5 |
8 |
Correct |
0 ms |
348 KB |
n=8 |
9 |
Incorrect |
0 ms |
348 KB |
Jury has the answer but participant has not |
10 |
Halted |
0 ms |
0 KB |
- |