#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vii;
typedef pair<ll,ll> pii;
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define pb push_back
const ll M=5e5+10;
const ll inf=2e18;
ll n,k,a[M],b[M],pre[M],suf[M],pm[M],sm[M];
int main() {
ios_base::sync_with_stdio(0),cin.tie(0);
cin>>n>>k;
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=0;i<n;i++)
cin>>b[i];
pre[0]=b[0];
for(int i=1;i<n;i++) {
pre[i]=pre[i-1]-b[i-1]+a[i-1]+b[i];
}
suf[0]=b[0]-a[0];
for(int i=1;i<n;i++) {
suf[i]=suf[i-1]-b[i-1]-a[i]+b[i];
}
pm[0]=pre[0];
for(int i=1;i<n;i++)
pm[i]=max(pre[i],pm[i-1]);
sm[n-1]=suf[n-1];
for(int i=n-2;i>=0;i--)
sm[i]=max(suf[i],sm[i+1]);
ll ans=-inf;
for(int i=0;i<n-1;i++) {
ans=max(ans,pre[i]+sm[i+1]);
}
cout<<ans<<'\n';
for(int i=0;i<n;i++) {
if(i<n-1&&pre[i]+sm[i+1]==ans)
cout<<1;
else if(i>0&&suf[i]+pm[i-1]==ans)
cout<<1;
else
cout<<0;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
10588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
10588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
10588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
10588 KB |
Output is correct |
2 |
Correct |
33 ms |
23244 KB |
Output is correct |
3 |
Correct |
37 ms |
23292 KB |
Output is correct |
4 |
Correct |
33 ms |
23296 KB |
Output is correct |
5 |
Correct |
35 ms |
23632 KB |
Output is correct |
6 |
Correct |
34 ms |
23388 KB |
Output is correct |
7 |
Correct |
33 ms |
23376 KB |
Output is correct |
8 |
Correct |
35 ms |
23376 KB |
Output is correct |
9 |
Correct |
27 ms |
23380 KB |
Output is correct |
10 |
Correct |
32 ms |
23388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
10588 KB |
Output is correct |
2 |
Correct |
33 ms |
23244 KB |
Output is correct |
3 |
Correct |
37 ms |
23292 KB |
Output is correct |
4 |
Correct |
33 ms |
23296 KB |
Output is correct |
5 |
Correct |
35 ms |
23632 KB |
Output is correct |
6 |
Correct |
34 ms |
23388 KB |
Output is correct |
7 |
Correct |
33 ms |
23376 KB |
Output is correct |
8 |
Correct |
35 ms |
23376 KB |
Output is correct |
9 |
Correct |
27 ms |
23380 KB |
Output is correct |
10 |
Correct |
32 ms |
23388 KB |
Output is correct |
11 |
Correct |
1 ms |
10584 KB |
Output is correct |
12 |
Correct |
29 ms |
23380 KB |
Output is correct |
13 |
Correct |
38 ms |
23376 KB |
Output is correct |
14 |
Correct |
34 ms |
23260 KB |
Output is correct |
15 |
Correct |
34 ms |
23256 KB |
Output is correct |
16 |
Correct |
32 ms |
23380 KB |
Output is correct |
17 |
Correct |
32 ms |
23380 KB |
Output is correct |
18 |
Correct |
35 ms |
23376 KB |
Output is correct |
19 |
Correct |
27 ms |
23376 KB |
Output is correct |
20 |
Correct |
30 ms |
23384 KB |
Output is correct |
21 |
Incorrect |
1 ms |
10588 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
10588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |