#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
2380 KB |
Output is correct |
2 |
Correct |
22 ms |
2160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
2508 KB |
Output is correct |
2 |
Correct |
21 ms |
2252 KB |
Output is correct |
3 |
Correct |
21 ms |
2416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
191 ms |
18032 KB |
Output is correct |
2 |
Correct |
202 ms |
18764 KB |
Output is correct |
3 |
Correct |
251 ms |
19664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
268 ms |
22680 KB |
Output is correct |
2 |
Correct |
347 ms |
81712 KB |
Output is correct |
3 |
Correct |
313 ms |
24904 KB |
Output is correct |
4 |
Correct |
263 ms |
21868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
319 ms |
24320 KB |
Output is correct |
2 |
Correct |
265 ms |
26604 KB |
Output is correct |
3 |
Correct |
289 ms |
23188 KB |
Output is correct |
4 |
Correct |
333 ms |
25188 KB |
Output is correct |