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;
const int MAXN = 1000010;
int v[MAXN];
int Indices[MAXN];
/*struct team
{
int ini;
int fim;
bool operator<(team outro)
{
return fim - ini < outro.fim - outro.ini;
}
};*/
set<pair<int, pair<int, int> > > teams;
bool cmp(int a, int b)
{
return v[a] < v[b];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin >> N;
for (int i = 1; i <= N; i++) {cin >> v[i]; Indices[i] = i;}
sort(Indices+1, Indices+N+1, cmp);
for (int i = N; i > 0; i--)
{
if (i - (v[Indices[i]] - 1) > 0)
{
int ini = i - (v[Indices[i]] - 1);
int fim = i;
teams.insert(make_pair(fim - ini, make_pair(ini, fim) ) );
i -= (v[Indices[i]] - 1);
}
else
{
pair<int, int> smallTeam;
smallTeam = (*teams.begin()).second;
teams.erase(teams.begin());
smallTeam.first = i;
teams.insert(make_pair(smallTeam.second - smallTeam.first, smallTeam));
}
}
cout << teams.size();
for (auto it : teams)
{
pair<int, int> curTeam = it.second;
cout << '\n';
cout << (it.first + 1);
for (int i = curTeam.first; i <= curTeam.second; i++) cout << " " << Indices[i];
}
}
# | 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... |