1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <bits/stdc++.h>

using namespace std;
int n;
long long int a[200000];
int result = 0;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> n;
    for(int i = 0; i < n; i ++){
        cin >> a[i];
    }
    int last = a[0];
    for(int i = 1; i < n; i ++){
        if(a[i] <= last){
            int diff = log10(last) - log10(a[i]);
            if(diff < 2) diff = 1;
            else diff --;
            while(1){
                if(a[i] * (pow(10, diff)) > last){
                    a[i] *= pow(10, diff);
                    result += diff;
                    break;
                }
                if(last - (a[i] * pow(10, diff)) + 1 < pow(10, diff)){
                    a[i] = last + 1;
                    result += diff;
                    break;
                }
                diff ++;
            }

        }
        last = a[i];
    }
    cout << result;
    return 0;
}