QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#46821 | #4591. Maxdifficent Group | abcde | WA | 13ms | 4932kb | C++ | 2.3kb | 2022-09-01 23:30:03 | 2022-09-01 23:30:04 |
Judging History
answer
#include<bits/stdc++.h>
#define fr(i,j,n) for(int i=j;i<n;i++)
#define pb push_back
#define rf(i,j,p) for(int i=p-1;i>=j;i--)
#define vi vector<int>
#define vll vector<long long>
#define ll long long
#define hmm "\n"
#define sp " "
#define srt(v) sort(v.begin(), v.EEnd());
#define ww int tc ; cin >> tc ; while(tc--)
#define down cout<<hmm;
#define faaast ios_base::sync_with_stdio(0);cin.tie(nullptr);
#include <iostream>
#include <fstream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
//#define ordered_set tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll max_so_far, max_EEnding_here ;
ll start, EEnd , s;
void maxSubArraySum(ll a[], int size)
{
start =0, EEnd = 0, s=0;
max_so_far = LLONG_MIN, max_EEnding_here = 0;
for (int i=0; i< size; i++ )
{
max_EEnding_here += a[i];
if (max_so_far < max_EEnding_here)
{
max_so_far = max_EEnding_here;
start = s;
EEnd = i;
}
if (max_EEnding_here < 0)
{
max_EEnding_here = 0;
s = i + 1;
}
}
//max so far , EEnd ;
}
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int n ; cin >> n ;
ll arr[n]; ll cum[n];
fr(i,0,n)cin >> arr[i], cum[i]=arr[i];
maxSubArraySum( arr, n);
if(start == 0 && EEnd == n-1){
fr(i,1,n)cum[i]+=cum[i-1];
ll mx = 0 ;
mx = abs(cum[n-1]-(ll)2*arr[0]);
mx = max(mx , abs(cum[n-1]-2*arr[n-1]));
fr(i,1,n-1){
mx = max(mx ,abs(cum[i-1]-arr[i]));
mx = max(mx, abs(cum[n-1]-cum[i]-arr[i]));
}
cout<<mx<<hmm;
return 0;
}
ll mx = 0, sum=0 ;
for(int i = start -1 ; i >=0 ; i--){
sum += arr[i];
mx = max(mx, abs(max_so_far-sum));
}
sum = 0 ;
fr(i,EEnd+1, n)
{
sum += arr[i];
mx = max(mx, abs(max_so_far-sum));
}
cout<<mx<<hmm;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 3568kb
input:
4 100 -30 -20 50
output:
150
result:
ok single line: '150'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3592kb
input:
5 12 7 4 32 9
output:
46
result:
ok single line: '46'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
6 -5 10 -5 45 -20 15
output:
70
result:
ok single line: '70'
Test #4:
score: 0
Accepted
time: 2ms
memory: 3616kb
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: 0
Accepted
time: 2ms
memory: 3656kb
input:
2 0 -900000
output:
900000
result:
ok single line: '900000'
Test #6:
score: 0
Accepted
time: 9ms
memory: 4464kb
input:
59394 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 11ms
memory: 4472kb
input:
63744 -1 0 1 1 0 0 1 -1 -1 -1 -1 -1 1 1 1 -1 0 0 1 1 1 -1 1 -1 1 1 0 1 1 1 1 0 1 1 1 1 1 0 0 1 0 1 -1 1 1 1 -1 1 -1 0 0 -1 -1 1 1 0 0 0 1 0 -1 -1 0 0 0 1 -1 0 1 0 0 1 -1 -1 0 0 -1 -1 1 0 1 0 1 0 -1 0 -1 1 1 -1 1 1 -1 1 -1 1 0 0 -1 1 1 0 0 -1 0 0 1 0 0 1 -1 1 0 1 0 -1 0 0 1 0 0 -1 0 0 0 -1 0 0 1 -1 -...
output:
475
result:
ok single line: '475'
Test #8:
score: 0
Accepted
time: 13ms
memory: 4932kb
input:
87255 4 -9 3 -3 -2 -2 3 10 -7 -10 -5 5 -9 -7 1 -1 10 0 -1 1 10 -9 -8 8 5 -8 2 -3 -7 7 -5 -3 3 -2 5 -1 -5 6 -2 8 3 0 -6 5 -10 5 0 -8 -3 -1 -7 -3 0 7 -4 5 -1 -5 -9 -2 8 7 6 -2 6 9 -2 6 10 3 10 -10 4 5 -9 0 -10 -9 -10 6 9 -5 -3 -7 -2 -4 6 4 7 -4 4 2 -8 -2 -4 3 2 -9 -4 9 3 8 -5 -1 8 -10 8 -3 -6 7 -1 8 -...
output:
5780
result:
ok single line: '5780'
Test #9:
score: 0
Accepted
time: 8ms
memory: 3952kb
input:
22859 123270 568778 416102 510776 597790 125263 860375 89550 16897 909046 124583 592535 32050 175429 993750 899188 863104 608753 724971 728319 82786 733737 923128 266621 57189 518044 556356 756193 408537 94718 998619 206034 125763 649241 204930 474150 57466 358193 153011 416494 753281 480726 927554 ...
output:
11402652338
result:
ok single line: '11402652338'
Test #10:
score: -100
Wrong Answer
time: 8ms
memory: 4236kb
input:
33834 -514303 -172893 -206523 -8184 -343624 -208669 -690452 -17023 -342571 -830835 -999032 -533750 -822347 -62447 -85968 -172653 -485779 -40414 -37219 -564266 -427415 -565431 -197676 -911379 -238653 -602443 -410483 -122721 -921143 -764784 -355380 -23053 -510189 -547702 -165836 -672416 -12018 -966618...
output:
12713187488
result:
wrong answer 1st lines differ - expected: '16851470332', found: '12713187488'