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()
vi konstruct(vpii &A, int limit)
{
    int n = sz(A);
    vi last(n + 1, -1);
    vi dp(n + 1, 0);
    vi lastMaxIdx(n + 1, 0);
    for (int i = 1; i <= n; ++i)
    {
        // interval to search: [ i - limit, i - A[i].first ] (inclusive borders)
        int teams, la;
        if (i >= A[i - 1].first)
        {
            int tmp = lastMaxIdx[i - A[i - 1].first];
            if (tmp < i - limit)
                teams = -1, la = -1;
            else
                teams = dp[tmp] + 1, la = tmp;
        }
        else
        {
            teams = -1, la = -1;
        }
        dp[i] = teams;
        last[i] = la;
        lastMaxIdx[i] = lastMaxIdx[i - 1];
        if (dp[i] >= dp[lastMaxIdx[i]])
            lastMaxIdx[i] = i;
    }
    vi ans;
    int idx = n;
    while (idx > 0)
    {
        ans.push_back(idx - 1);
        idx = last[idx];
    }
    return ans;
}
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 + 1;
    sort(all(A));
    int opt = sz(konstruct(A, n));
    int l = A.back().first, r = n;
    while (l < r)
    {
        int m = (l + r) / 2;
        int ans = sz(konstruct(A, m));
        if (ans < opt)
            l = m + 1;
        else
            r = m;
    }
    vi order = konstruct(A, l);
    reverse(all(order));
    cout << sz(order) << "\n";
    int idx = 0;
    for (int x : order)
    {
        cout << x - idx + 1 << " ";
        while (idx <= x)
            cout << A[idx++].second << " ";
        cout << "\n";
    }
    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... |