QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#305414#4591. Maxdifficent GroupLeeShoW#WA 0ms3656kbC++20853b2024-01-15 10:56:192024-01-15 10:56:19

Judging History

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

  • [2024-01-15 10:56:19]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3656kb
  • [2024-01-15 10:56:19]
  • 提交

answer

#include<iostream>
#include<algorithm>
#include<random>
#include<vector>
#include<chrono>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#define pii pair<int,int>
#define int long long
using namespace std;
signed main(){
    int n;
    cin>>n;
    int all[n+1];
    int dp[n+1];
    int rdp[n+1];
    for(int i=1;i<=n;i++){
        cin>>all[i];
    }
    for(int i=1;i<=n;i++){
        if(i==1){
            dp[i]=all[i];
        }else {
            dp[i]=max(dp[i-1]+all[i],all[i]);
        }
    }
    for(int i=n;i>=1;i--){
        if(i==n){
            rdp[i]=all[i];
        }else rdp[i]=min(all[i],rdp[i+1]+all[i]);
    }
    int ans=-1e10;
    for(int i=1;i<n;i++){
        //cout<<dp[i]<<" "<<rdp[i+1]<<endl;
        ans=max(ans,dp[i]-rdp[i+1]);
    }
    cout<<ans<<endl;

    return 0;
}

详细

Test #1:

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

input:

4
100 -30 -20 50

output:

150

result:

ok single line: '150'

Test #2:

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

input:

5
12 7 4 32 9

output:

46

result:

ok single line: '46'

Test #3:

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

input:

6
-5 10 -5 45 -20 15

output:

70

result:

ok single line: '70'

Test #4:

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

input:

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

output:

32

result:

wrong answer 1st lines differ - expected: '41', found: '32'