题解 | #降温(easy)#

降温(easy)

https://ac.nowcoder.com/acm/problem/281749

分别模拟求出最大最小值即可

from sys import stdin, stdout
def main():
    input = stdin.readline
    n,x = map(int,input().split())
    if n == 1:
        print("0 0")
        return
    l = [int(i) for i in input().split()]
    cntmax = 0
    cntmin = 0
    # cntmax
    if l[0] != -999:
        start = l[0]
    else:
        start = 50
    for i in range(1,n):
        if l[i] != -999:
            if start-l[i] >= x:
                cntmax += 1
            start = l[i]
        else:
            if start-x>= -50:
                start -= x
                cntmax += 1
            else:
                start = 50
    # cntmin
    if l[0] != -999:
        start = l[0]
    else:
        start = -50
    for i in range(1,n):
        if l[i] != -999:
            if start-l[i] >= x:
                cntmin += 1
            start = l[i]
        else:
            start = max(-50,start - x + 1)
    print(cntmax,cntmin)
if __name__ == "__main__":
    main()
全部评论

相关推荐

2024-12-11 00:12
门头沟学院 Java
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务