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 ii pair < int , int >
#define fi first
#define se second
#define int long long
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
using namespace std;
void maximize(int &A, int B)
{
if(A < B) A = B;
return;
}
void minimize(int &A, int B)
{
if(A > B) A = B;
return;
}
const int N = 1e3 + 5;
const int mod = 1e9 + 7;
int n;
ii a[N];
vector < int > team[N];
priority_queue < ii , vector < ii > , greater < ii > > q;
bool cmp(ii a, ii b)
{
return a.fi > b.fi;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
FOR(i, 1, n){
cin >> a[i].fi;
a[i].se = i;
}
sort(a + 1, a + n + 1, cmp);
int cnt = 0, save = n + 1;
FOR(i, 1, n){
if(i + a[i].fi - 1 > n){
save = i;
break;
}
cnt++;
for(int j = i; j <= i + a[i].fi - 1; j++){
team[cnt].push_back(a[j].se);
}
i = i + a[i].fi - 1;
}
FOR(i, 1, cnt){
q.push(ii((int)team[i].size(), i));
}
FOR(i, save, n){
int I = q.top().se;
q.pop();
team[I].push_back(a[i].se);
q.push(ii((int)team[I].size(), I));
}
cout << cnt << '\n';
FOR(i, 1, cnt){
cout << (int)team[i].size() << " ";
for(int &v : team[i]){
cout << v << " ";
}
cout << '\n';
}
}
# | 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... |
# | 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... |