107992024-04-14 11:45:23AblablablaÖsszegzésekcpp17Accepted 100/10010ms4756 KiB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;

    vector<int> alap(n);
    int osszeg = 0;
    for(int i = 0; i < n; i++){
        cin >> alap[i];
        osszeg += alap[i];
    }

    int novelInd = 0;
    int elotte = osszeg;
    for(int i = n - 1; i >= 1; i--){
        if(alap[i] != alap[i - 1] && elotte + 1 <= osszeg){
            novelInd = i;
            break;
        }
        elotte -= alap[i];
    }

    if(n == 1){
        cout << "0\n";
    } else{
        int mas = osszeg;
        for(int i = 0; i < novelInd; i++){
            cout << alap[i] << " ";
            mas -= alap[i];
        }
        cout << alap[novelInd] + 1 << " ";
        mas -= alap[novelInd] + 1;
        while(mas > 0){
            cout << "1 ";
            mas--;
        }
        cout << "\n";
    }

    int csokkInd = -1;
    for(int i = n - 1; i >= 0; i--){
        if(alap[i] != 1){
            csokkInd = i;
            break;
        }
    }

    if(n == osszeg){
        cout << "0\n";
    } else{
        int mas = osszeg;
        for(int i = 0; i < csokkInd; i++){
            cout << alap[i] << " ";
            mas -= alap[i];
        }
        int akt = alap[csokkInd] - 1;
        cout << akt << " ";
        mas -= akt;
        while(mas >= akt){
            cout << akt << " ";
            mas -= akt;
        }

        if(mas != 0){
            cout << mas << " ";
        }
        cout << "\n";
    }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1712 KiB
2Accepted3ms2076 KiB
3Accepted3ms2216 KiB
subtask26/6
4Accepted3ms2088 KiB
5Accepted3ms2300 KiB
6Accepted3ms2552 KiB
7Accepted3ms2756 KiB
8Accepted3ms2960 KiB
subtask36/6
9Accepted3ms3016 KiB
10Accepted3ms3020 KiB
11Accepted3ms3260 KiB
12Accepted4ms3412 KiB
13Accepted4ms3612 KiB
subtask410/10
14Accepted3ms3016 KiB
15Accepted3ms3020 KiB
16Accepted3ms3260 KiB
17Accepted4ms3412 KiB
18Accepted4ms3612 KiB
19Accepted3ms3436 KiB
20Accepted3ms3528 KiB
21Accepted9ms3560 KiB
22Accepted10ms3560 KiB
23Accepted9ms3904 KiB
subtask510/10
24Accepted2ms3736 KiB
25Accepted3ms3736 KiB
26Accepted3ms3736 KiB
27Accepted3ms3852 KiB
28Accepted3ms3868 KiB
subtask610/10
29Accepted3ms3996 KiB
30Accepted3ms3996 KiB
31Accepted3ms4084 KiB
32Accepted3ms4084 KiB
33Accepted3ms4200 KiB
subtask758/58
34Accepted3ms4200 KiB
35Accepted2ms4200 KiB
36Accepted3ms4204 KiB
37Accepted3ms2088 KiB
38Accepted3ms2300 KiB
39Accepted3ms2552 KiB
40Accepted3ms2756 KiB
41Accepted3ms2960 KiB
42Accepted3ms3016 KiB
43Accepted3ms3020 KiB
44Accepted3ms3260 KiB
45Accepted4ms3412 KiB
46Accepted4ms3612 KiB
47Accepted3ms3436 KiB
48Accepted3ms3528 KiB
49Accepted9ms3560 KiB
50Accepted10ms3560 KiB
51Accepted3ms3868 KiB
52Accepted3ms3996 KiB
53Accepted3ms3996 KiB
54Accepted3ms4084 KiB
55Accepted3ms4084 KiB
56Accepted3ms4200 KiB
57Accepted3ms4088 KiB
58Accepted3ms4208 KiB
59Accepted3ms4424 KiB
60Accepted3ms4512 KiB
61Accepted3ms4508 KiB
62Accepted3ms4512 KiB
63Accepted3ms4628 KiB
64Accepted4ms4644 KiB
65Accepted4ms4740 KiB
66Accepted7ms4756 KiB