forked from marioyc/Online-Judge-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3627 - Treasure Hunt II.cpp
47 lines (32 loc) · 1.03 KB
/
3627 - Treasure Hunt II.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <cstdio>
#include <algorithm>
using namespace std;
#define MAXN 100005
int main(){
int n,p,v[MAXN],M,T;
long long sum[MAXN];
while(scanf("%d %d",&n,&p) == 2){
sum[0] = 0;
for(int i = 0;i < n;++i){
scanf("%d",&v[i]);
sum[i + 1] = sum[i] +v[i];
}
scanf("%d %d",&M,&T);
long long ans = 0;
for(int i = 1;i <= p;++i){
int lo = p - 1,hi = n,mi;
while(lo < hi){
mi = (lo + hi + 1) >> 1;
int z1 = min(mi,min(2 * p - i,i + M));
int t1 = p - i + mi - z1;
int z2 = max(i,max(2 * p - mi,mi - M));
int t2 = mi - p + z2 - i;
if(min(t1,t2) > T) hi = mi - 1;
else lo = mi;
}
if(lo >= p) ans = max(ans,sum[lo] - sum[i - 1]);
}
printf("%lld\n",ans);
}
return 0;
}