107052024-04-10 09:42:21szilÖsszegzésekcpp17Accepted 100/10017ms4744 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int MAXN = 100'001;

int a[MAXN];

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, szum = 0; cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        szum += a[i];
    }
    if (n == 1) {
        cout << "0\n";
    } else {
        int k = a[n-1] + 1;
        vector<int> ans;
        for (int i = 1; i <= n; i++) {
            if (a[i] < k && i != n-1) {
                for (int j = 0; j < a[i] - (i == n); j++) ans.emplace_back(1);
            }
            else {
                if (i == n-1) {
                    ans.emplace_back(a[i]+1);
                }
                else {
                    ans.emplace_back(a[i]);
                }
            }
        }
        sort(ans.rbegin(), ans.rend());
        for (int i : ans) {
            cout << i << " ";
        }
        cout << "\n";
    }
    if (n == szum) {
        cout << "0\n";
    } else {
        int pos = 0;
        for (int i = 1; i <= n; i++) {
            if (a[i] >= 2) pos = i; 
        }
        int x = 1;
        for (int i = pos+1; i <= n; i++) {
            x += a[i];
        }
        vector<int> ans = {a[pos] - 1};
        for (int i = 1; i < pos; i++) ans.emplace_back(a[i]);
        while (x > 0) {
            ans.emplace_back(min(a[pos] - 1, x));
            x -= min(a[pos] - 1, x);
        }
        sort(ans.rbegin(), ans.rend());
        for (int i : ans) {
            if (i > 0) cout << i << " ";
        }
        cout << "\n";
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1712 KiB
2Accepted3ms1924 KiB
3Accepted3ms2284 KiB
subtask26/6
4Accepted3ms2456 KiB
5Accepted3ms2560 KiB
6Accepted2ms2644 KiB
7Accepted2ms2732 KiB
8Accepted3ms2724 KiB
subtask36/6
9Accepted3ms2932 KiB
10Accepted3ms3148 KiB
11Accepted3ms3240 KiB
12Accepted4ms3636 KiB
13Accepted4ms3592 KiB
subtask410/10
14Accepted3ms2932 KiB
15Accepted3ms3148 KiB
16Accepted3ms3240 KiB
17Accepted4ms3636 KiB
18Accepted4ms3592 KiB
19Accepted3ms3276 KiB
20Accepted3ms3336 KiB
21Accepted14ms4704 KiB
22Accepted17ms4744 KiB
23Accepted14ms4680 KiB
subtask510/10
24Accepted3ms3504 KiB
25Accepted3ms3660 KiB
26Accepted3ms3652 KiB
27Accepted3ms3652 KiB
28Accepted3ms3660 KiB
subtask610/10
29Accepted3ms3868 KiB
30Accepted2ms3652 KiB
31Accepted3ms3780 KiB
32Accepted2ms3864 KiB
33Accepted2ms3876 KiB
subtask758/58
34Accepted2ms3872 KiB
35Accepted2ms3872 KiB
36Accepted3ms3888 KiB
37Accepted3ms2456 KiB
38Accepted3ms2560 KiB
39Accepted2ms2644 KiB
40Accepted2ms2732 KiB
41Accepted3ms2724 KiB
42Accepted3ms2932 KiB
43Accepted3ms3148 KiB
44Accepted3ms3240 KiB
45Accepted4ms3636 KiB
46Accepted4ms3592 KiB
47Accepted3ms3276 KiB
48Accepted3ms3336 KiB
49Accepted14ms4704 KiB
50Accepted17ms4744 KiB
51Accepted3ms3660 KiB
52Accepted3ms3868 KiB
53Accepted2ms3652 KiB
54Accepted3ms3780 KiB
55Accepted2ms3864 KiB
56Accepted2ms3876 KiB
57Accepted3ms3888 KiB
58Accepted3ms3996 KiB
59Accepted3ms4084 KiB
60Accepted3ms4084 KiB
61Accepted3ms4172 KiB
62Accepted3ms4184 KiB
63Accepted3ms4184 KiB
64Accepted3ms4136 KiB
65Accepted4ms4328 KiB
66Accepted6ms4484 KiB