QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#319174 | #4591. Maxdifficent Group | ssuyu | WA | 1ms | 3608kb | C++17 | 1.3kb | 2024-02-02 03:20:34 | 2024-02-02 03:20:34 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ssuyu \
ios_base::sync_with_stdio(0); \
cin.tie(0)
#define pb push_back
#define F first
#define S second
#define pii pair<int, int>
#define int long long
#define PI acos(-1)
#define all(x) (x).begin(), (x).end()
const int N = 1e5 + 5;
int n, a[N] = {0}, dpmx1[N], dpmx2[N], dpmn1[N], dpmn2[N], ans = -1;
signed main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
dpmx1[0] = dpmn2[0] = a[0];
for (int i = 1; i < n; i++) {
dpmx1[i] = max(dpmx1[i - 1] + a[i], a[i]);
dpmn2[i] = min(dpmn2[i - 1] + a[i], a[i]);
}
for (int i = 1; i < n; i++) {
dpmx1[i] = max(dpmx1[i - 1] + a[i], a[i]);
dpmn2[i] = min(dpmn2[i - 1] + a[i], a[i]);
}
reverse(a, a + n);
dpmn1[0] = dpmx2[0] = a[0];
for (int i = 1; i < n; i++) {
dpmx2[i] = max(dpmx2[i - 1] + a[i], a[i]);
dpmn1[i] = min(dpmn1[i - 1] + a[i], a[i]);
}
for (int i = 0; i < n; i++) {
ans = max(ans, abs(dpmx1[i] - dpmn1[n - i - 2]));
ans = max(ans, abs(dpmx2[i] - dpmn2[n - i - 2]));
}
cout << ans;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3540kb
input:
4 100 -30 -20 50
output:
150
result:
ok single line: '150'
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3608kb
input:
5 12 7 4 32 9
output:
64
result:
wrong answer 1st lines differ - expected: '46', found: '64'