# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
89521 | RAkhshon | Gift (IZhO18_nicegift) | C++17 | 2033 ms | 79992 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ll long long
#define fr first
#define se second
using namespace std;
set< pair< ll, ll > > st;
vector< ll > ans;
int main(){
ll n, k;
cin>>n>>k;
for( ll i =1 ; i <= n ; i ++ ){
ll x;
cin>>x;
st.insert({x,i});
}
/***
std::pair<ll,ll> x;
x=*st.rbegin();
st.erase(x);
***/
ans.push_back(-1);
std::vector< pair<ll,ll> > help;
while( st.size()>k-1 ){
ll t = k;
ans.push_back(1);
while( t > 0 ){
std::pair< ll , ll > x;
x=*st.rbegin();
st.erase(*st.rbegin());
///cout<<x.fr<<'#'<<x.se<<endl;
if( x.fr != 1 ) help.push_back({x.fr-1,x.se});
ans.push_back(x.se);
t--;
}
///cout<<help.size()<<'!'<<endl;
if( help.size() != 0 ){
for( ll i = help.size()-1 ; i >= 0 ; i -- ) {
st.insert(help[i]);
}
help.clear();
}
///cout<<st.size()<<endl;
}
if( st.size() < k && st.size()!=0 ){
cout<<-1;
return 0;
}
cout<<(ans.size()-1)/(k+1)<<endl;
for( ll i = 1; i < ans.size(); i ++ ){
cout<<ans[i]<<' ';
if( (i)%(k+1)==0 ) cout<<endl;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |