109932024-05-03 12:39:16EsVagyÖsszegzésekcpp17Accepted 100/10019ms788 KiB
#include <bits/stdc++.h>
using namespace std;
using t = int;

int main() {
  t size;
  cin >> size;
  vector<t> vec(size);
  for (t i = 0; i < size; i++) {
    cin >> vec[i];
  }

  {
    t last = vec[vec.size() - 1];
    t index = vec.size() - 1;
    t sum = 0;
    while (true) {
      if (index == -1) {
        cout << "0\n";
        break;
      }

      sum += vec[index];
      if (vec[index - 1] != last || index == 0) {
        if (sum == last) {
          last = vec[index - 1];
          index--;
          continue;
        }

        for (t i = 0; i < index; i++) {
          cout << vec[i] << " ";
        }
        cout << last + 1 << " ";
        sum -= last + 1;
        while (sum > 0) {
          cout << 1 << " ";
          sum--;
        }
        cout << "\n";
        break;
      }
      index--;
    }
  }
  {
    t index = vec.size() - 1;
    t sum = 0;
    while (true) {
      if (index == -1) {
        cout << "0\n";
        break;
      }
      sum += vec[index];
      if (vec[index] == 1) {
        index--;
        continue;
      }

      for (t i = 0; i < index; i++) {
        cout << vec[i] << " ";
      }
      cout << vec[index] - 1 << " ";
      sum -= vec[index] - 1;
      while (sum > 0) {
        cout << min(sum, vec[index] - 1) << " ";
        sum -= min(sum, vec[index] - 1);
      }
      cout << "\n";
      break;
    }
  }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted2ms492 KiB
2Accepted3ms612 KiB
3Accepted3ms356 KiB
subtask26/6
4Accepted2ms412 KiB
5Accepted2ms356 KiB
6Accepted2ms512 KiB
7Accepted2ms356 KiB
8Accepted2ms420 KiB
subtask36/6
9Accepted2ms356 KiB
10Accepted3ms408 KiB
11Accepted3ms408 KiB
12Accepted4ms500 KiB
13Accepted4ms536 KiB
subtask410/10
14Accepted2ms356 KiB
15Accepted3ms408 KiB
16Accepted3ms408 KiB
17Accepted4ms500 KiB
18Accepted4ms536 KiB
19Accepted3ms356 KiB
20Accepted3ms504 KiB
21Accepted17ms612 KiB
22Accepted19ms788 KiB
23Accepted17ms540 KiB
subtask510/10
24Accepted3ms484 KiB
25Accepted3ms484 KiB
26Accepted3ms636 KiB
27Accepted3ms656 KiB
28Accepted2ms376 KiB
subtask610/10
29Accepted3ms484 KiB
30Accepted3ms420 KiB
31Accepted3ms536 KiB
32Accepted3ms384 KiB
33Accepted2ms376 KiB
subtask758/58
34Accepted2ms384 KiB
35Accepted3ms484 KiB
36Accepted3ms360 KiB
37Accepted2ms412 KiB
38Accepted2ms356 KiB
39Accepted2ms512 KiB
40Accepted2ms356 KiB
41Accepted2ms420 KiB
42Accepted2ms356 KiB
43Accepted3ms408 KiB
44Accepted3ms408 KiB
45Accepted4ms500 KiB
46Accepted4ms536 KiB
47Accepted3ms356 KiB
48Accepted3ms504 KiB
49Accepted17ms612 KiB
50Accepted19ms788 KiB
51Accepted2ms376 KiB
52Accepted3ms484 KiB
53Accepted3ms420 KiB
54Accepted3ms536 KiB
55Accepted3ms384 KiB
56Accepted2ms376 KiB
57Accepted3ms504 KiB
58Accepted2ms376 KiB
59Accepted2ms376 KiB
60Accepted3ms500 KiB
61Accepted2ms484 KiB
62Accepted3ms356 KiB
63Accepted3ms504 KiB
64Accepted4ms376 KiB
65Accepted4ms376 KiB
66Accepted7ms484 KiB