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"
using namespace std;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vpii A(n);
for (int i = 0; i < n; ++i)
cin >> A[i].first, A[i].second = i;
sort(all(A), greater<pii>());
vvi teams;
int cnt = 0;
priority_queue<pii, vpii, greater<pii>> q;
while (cnt < n)
{
if (A[cnt].first <= n - cnt)
{
teams.push_back(vi());
for (int d = 0; d < A[cnt].first; ++d)
teams.back().push_back(A[cnt + d].second);
q.push({sz(teams.back()), sz(teams) - 1});
cnt += A[cnt].first;
}
else
{
int size, team;
tie(size, team) = q.top();
q.pop();
teams[team].push_back(A[cnt].second);
++size, ++cnt;
q.push({size, team});
}
}
cout << sz(teams) << "\n";
for (vi team : teams)
{
cout << sz(team);
for (int p : team)
cout << " " << p + 1;
cout << "\n";
}
return 0;
}
# | 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... |