QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#706564#4591. Maxdifficent Grouparnold518#WA 0ms3808kbC++171012b2024-11-03 12:16:052024-11-03 12:16:05

Judging History

你现在查看的是最新测评结果

  • [2024-11-03 12:16:05]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3808kb
  • [2024-11-03 12:16:05]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

lint N;
vector<lint> a;

lint solve(vector<lint> v) {
    lint N = v.size();

    vector<lint> sum = {v[0]}, pfx, sfx;

    for (int i=1; i<N; i++) sum.push_back(sum[i-1] + v[i]);

    pfx.resize(N);
    sfx.resize(N);

    pfx[0] = sum[0];
    for (int i=1; i<N; i++) pfx[i] = max(pfx[i-1], sum[i]);

    sfx[N-1] = sum[N-1];
    for (int i=N-2; i>=0; i--) sfx[i] = max(sfx[i+1], sum[i]);

    lint ans = 0;
    for (int k=0; k<N; k++) {
        lint now = -2 * sum[k];

        if (k > 0) now += pfx[k-1];
        if (k < N-1) now += sfx[k+1];

        ans = max(ans, now);
    }

    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    
    cin >> N;

    a.resize(N);
    for (int i=0; i<N; i++) cin >> a[i];

    lint ans = solve(a);

    reverse(a.begin(), a.end());

    ans = max(ans, solve(a));

    cout << ans << '\n';
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3808kb

input:

4
100 -30 -20 50

output:

150

result:

ok single line: '150'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3536kb

input:

5
12 7 4 32 9

output:

46

result:

ok single line: '46'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3524kb

input:

6
-5 10 -5 45 -20 15

output:

70

result:

ok single line: '70'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

14
1 5 3 4 2 -4 -2 -6 -5 6 4 2 3 9

output:

41

result:

ok single line: '41'

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3604kb

input:

2
0 -900000

output:

1800000

result:

wrong answer 1st lines differ - expected: '900000', found: '1800000'