# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
963366 | MilosMilutinovic | Gift (IZhO18_nicegift) | C++14 | 55 ms | 17820 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 pb push_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}
ll readint(){
ll x=0,f=1; char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,k;
int a[2000005];
int main(){
n=readint(); k=readint();
for(int i=1;i<=n;i++) a[i]=readint();
set<pii> st;
for(int i=1;i<=n;i++) if(a[i]>0) st.emplace(a[i],i);
vector<vector<int>> ans;
while(!st.empty()){
if(st.size()<k){
printf("-1\n");
return 0;
}
ans.pb({});
for(int i=1;i<=k;i++){
auto it=prev(st.end());
ans.back().pb(it->se);
a[it->se]--;
st.erase(it);
}
for(int i:ans.back()){
if(a[i]>0) st.emplace(a[i],i);
}
}
printf("%d\n",ans.size());
for(auto p:ans){
printf("1 ");
for(int i=0;i<(int)p.size();i++){
printf("%d ",p[i]);
}
printf("\n");
}
return 0;
}
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... |