121B.md (1952B)
1 Source: https://codeforces.com/problemset/problem/121/B 2 3 B. Lucky Transformation 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 stdin 16 17 output 18 19 stdout 20 21 Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. 22 23 Petya has a number consisting of *n* digits without leading zeroes. He represented it as an array of digits without leading zeroes. Let's call it *d*. The numeration starts with 1, starting from the most significant digit. Petya wants to perform the following operation *k* times: find the minimum *x* (1 ≤ *x* < *n*) such that *d**x* = 4 and *d**x* + 1 = 7, if *x* is odd, then to assign *d**x* = *d**x* + 1 = 4, otherwise to assign *d**x* = *d**x* + 1 = 7. Note that if no *x* was found, then the operation counts as completed and the array doesn't change at all. 24 25 You are given the initial number as an array of digits and the number *k*. Help Petya find the result of completing *k* operations. 26 27 Input 28 29 The first line contains two integers *n* and *k* (1 ≤ *n* ≤ 105, 0 ≤ *k* ≤ 109) — the number of digits in the number and the number of completed operations. The second line contains *n* digits without spaces representing the array of digits *d*, starting with *d*1. It is guaranteed that the first digit of the number does not equal zero. 30 31 Output 32 33 In the single line print the result without spaces — the number after the *k* operations are fulfilled. 34 35 Examples 36 37 Input 38 39 ``` 40 7 4 41 4727447 42 ``` 43 44 Output 45 46 ``` 47 4427477 48 ``` 49 50 Input 51 52 ``` 53 4 2 54 4478 55 ``` 56 57 Output 58 59 ``` 60 4478 61 ``` 62 63 Note 64 65 In the first sample the number changes in the following sequence: 4727447 → 4427447 → 4427477 → 4427447 → 4427477. 66 67 In the second sample: 4478 → 4778 → 4478.