Long Beautiful Integer CodeForces - 1268A(贪心构造)
You are given an integer x of n digits a1,a2,…,an, which make up its decimal notation in order from left to right.
Also, you are given a positive integer k<n.
Let’s call integer b1,b2,…,bm beautiful if bi=bi+k for each i, such that 1≤i≤m?k.
You need to find the smallest beautiful integer y, such that y≥x.
Input
The first line of input contains two integers n,k (2≤n≤200000,1≤k<n): the number of digits in x and k.
The next line of input contains n digits a1,a2,…,an (a1≠0, 0≤ai≤9): digits of x.
Output
In the first line print one integer m: the number of digits in y.
In the next line print m digits b1,b2,…,bm (b1≠0, 0≤bi≤9): digits of y.
Examples
Input
3 2
353
Output
3
353
Input
4 2
1234
Output
4
1313
思路:這個題目其實只要前k位確定了,那么這個數(shù)字就確定了。因為任意長度的全是9組成的數(shù)字一定符合題意,這樣m一定等于n。那么我們就取給定數(shù)字的前k位,剩下的根據(jù)這k位去構(gòu)造。如果大于等于給定的就直接輸出,否則就將前k位的數(shù)字+1,然后再根據(jù)這k位數(shù)字構(gòu)造。
代碼如下:
努力加油a啊,(o)/~
總結(jié)
以上是生活随笔為你收集整理的Long Beautiful Integer CodeForces - 1268A(贪心构造)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 阿里巴巴落户杭州余杭 10 周年,双方再
- 下一篇: 老人杀鱼感染海洋创伤弧菌致器官衰竭丧命: