#include<bits/stdc++.h>
#define ll long long
#define fr first
#define se second
using namespace std;
deque< pair<ll, ll> > d;
vector< pair<ll,pair< ll, ll> > > ans;
int main(){
ll n, k;
cin>>n>>k;
for( ll i =1 ; i <= n ; i ++ ){
ll x;
cin>>x;
d.push_back({x,i});
}
sort(d.begin(),d.end());
while(d.size()>1){
ll i = d.size()-1;
ll j = d.size()-2;
if( d[i].fr - d[j].fr > 0 ){
ll x = d[i].fr-d[j].fr;
ll ra = d[j].fr;
ll l = d[i].se;
ll r = d[j].se;
d.pop_back();
d.pop_back();
d.push_back({x,r});
ans.push_back({ra,{l,r}});
sort(d.begin(),d.end());
}
else if( d[i].fr - d[j].fr == 0 ) {
ll x = d[i].fr-d[j].fr;
ll ra = d[j].fr;
ll l = d[i].se;
ll r = d[j].se;
d.pop_back();
d.pop_back();
ans.push_back({ra,{l,r}});
}
/// cout<<d.size()<<endl;
}
if( d.size() == 1 ){
cout<<-1;
return 0;
}
cout<<ans.size()<<endl;
for( ll i = 0; i < ans.size(); i ++ ){
cout<<ans[i].fr<<' '<<ans[i].se.fr<<' '<<ans[i].se.se<<endl;
}
}
Compilation message
nicegift.cpp: In function 'int main()':
nicegift.cpp:32:13: warning: unused variable 'x' [-Wunused-variable]
ll x = d[i].fr-d[j].fr;
^
nicegift.cpp:48:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for( ll i = 0; i < ans.size(); i ++ ){
~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Incorrect |
2 ms |
388 KB |
Taken too much stones from the heap |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Incorrect |
2 ms |
388 KB |
Taken too much stones from the heap |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Incorrect |
2 ms |
388 KB |
Taken too much stones from the heap |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1699 ms |
34808 KB |
n=1000000 |
2 |
Incorrect |
1125 ms |
34808 KB |
Expected int32, but "1500001500001" found |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
n=4 |
2 |
Incorrect |
2 ms |
388 KB |
Taken too much stones from the heap |
3 |
Halted |
0 ms |
0 KB |
- |