1 条题解

  • 2
    @ 2025-2-11 16:47:55

    标题

    思路

    解题方法

    复杂度

    时间复杂度:

    添加时间复杂度, 示例: O(n)O(n)

    空间复杂度:

    添加空间复杂度, 示例: O(n)O(n)

    Code

    #include <bits/stdc++.h>
    using namespace std;
    #define int long long
    int n,x,t,ans,now,sum;
    signed main(){
        cin>>n>>x;
        for(int i = 1;i<=n;i++){
            cin>>t;
            sum+=t;
            now+=x-t;//将这个值赋值为 x 就等价于贡献了 x-t
            ans=max(ans,now);
            if(now<0) now=0;
        }
        cout<<ans+sum;
        return 0;
    }
    
    • 1

    信息

    ID
    110
    时间
    3000ms
    内存
    512MiB
    难度
    2
    标签
    递交数
    676
    已通过
    137
    上传者