急急急!帮我de一下bug谢谢
查看原帖
急急急!帮我de一下bug谢谢
970566
Programmer01楼主2025/1/16 09:43
#include <iostream>

#include <cstring>
using namespace std;

long long n, c, a[300005], s[300005], mins[300005];

long long maxs[300005];

int main()
{
    cin >> n >> c;
    
    memset(mins, 0x3f, sizeof mins);
    memset(maxs, -0x3f, sizeof maxs);
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        s[i] = s[i-1] + a[i];
        mins[i] = min(mins[i-1], s[i]);
        maxs[i] = max(maxs[i-1], s[i]);
    }
    long long ans = s[n];
    for(int i = 1; i <= n; i++)
    {
        if(c >= 1) ans = max(ans, s[n] + (s[i] - mins[i]) * (c-1));
        else ans = max(ans, s[n] + (s[i] - maxs[i]) * (c-1));
    }
	cout << ans << endl;
    return 0;
}
2025/1/16 09:43
加载中...