# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
89506 |
2018-12-15T07:00:59 Z |
RAkhshon |
Gift (IZhO18_nicegift) |
C++17 |
|
2000 ms |
17016 KB |
#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-1;
ll y = d[j].fr-1;
ll l = d[i].se;
ll r = d[j].se;
d.pop_back();
d.pop_back();
if( x > 0 )
d.push_back({x,l});
if( y > 0 )
d.push_back({y,r});
ans.push_back({1,{l,r}});
sort(d.begin(),d.end());
}
else if( d[i].fr - d[j].fr == 0 ) {
ll x = d[i].fr-1;
ll y = d[j].fr-1;
ll l = d[i].se;
ll r = d[j].se;
d.pop_back();
d.pop_back();
if( x > 0 )
d.push_back({x,l});
if( y > 0 )
d.push_back({y,r});
ans.push_back({1,{l,r}});
sort(d.begin(),d.end());
}
/// 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:55:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for( ll i = 0; i < ans.size(); i ++ ){
~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
400 KB |
n=3 |
4 |
Correct |
2 ms |
416 KB |
n=4 |
5 |
Correct |
2 ms |
604 KB |
n=4 |
6 |
Correct |
2 ms |
604 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
400 KB |
n=3 |
4 |
Correct |
2 ms |
416 KB |
n=4 |
5 |
Correct |
2 ms |
604 KB |
n=4 |
6 |
Correct |
2 ms |
604 KB |
n=2 |
7 |
Correct |
2 ms |
604 KB |
n=5 |
8 |
Correct |
3 ms |
1140 KB |
n=8 |
9 |
Correct |
30 ms |
1140 KB |
n=14 |
10 |
Correct |
18 ms |
1140 KB |
n=11 |
11 |
Execution timed out |
2008 ms |
1648 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
400 KB |
n=3 |
4 |
Correct |
2 ms |
416 KB |
n=4 |
5 |
Correct |
2 ms |
604 KB |
n=4 |
6 |
Correct |
2 ms |
604 KB |
n=2 |
7 |
Correct |
2 ms |
604 KB |
n=5 |
8 |
Correct |
3 ms |
1140 KB |
n=8 |
9 |
Correct |
30 ms |
1140 KB |
n=14 |
10 |
Correct |
18 ms |
1140 KB |
n=11 |
11 |
Execution timed out |
2008 ms |
1648 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2019 ms |
17016 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
n=4 |
2 |
Correct |
2 ms |
376 KB |
n=3 |
3 |
Correct |
2 ms |
400 KB |
n=3 |
4 |
Correct |
2 ms |
416 KB |
n=4 |
5 |
Correct |
2 ms |
604 KB |
n=4 |
6 |
Correct |
2 ms |
604 KB |
n=2 |
7 |
Correct |
2 ms |
604 KB |
n=5 |
8 |
Correct |
3 ms |
1140 KB |
n=8 |
9 |
Correct |
30 ms |
1140 KB |
n=14 |
10 |
Correct |
18 ms |
1140 KB |
n=11 |
11 |
Execution timed out |
2008 ms |
1648 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |