QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#305412 | #4591. Maxdifficent Group | LeeShoW# | WA | 1ms | 3556kb | C++20 | 930b | 2024-01-15 10:52:56 | 2024-01-15 10:52:57 |
Judging History
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 pre[n+1];
pre[0]=0;
int dp[n+1];
int rdp[n+1];
for(int i=1;i<=n;i++){
cin>>all[i];
pre[i]=pre[i-1]+all[i];
}
dp[0]=0;
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=0;
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3556kb
input:
4 100 -30 -20 50
output:
150
result:
ok single line: '150'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3420kb
input:
5 12 7 4 32 9
output:
46
result:
ok single line: '46'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3356kb
input:
6 -5 10 -5 45 -20 15
output:
70
result:
ok single line: '70'
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 3368kb
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'