-
Notifications
You must be signed in to change notification settings - Fork 0
/
sequencia2.cpp
executable file
·62 lines (52 loc) · 1.11 KB
/
sequencia2.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long int lli;
int main(){
lli N, L, H;
cin >> N >> L >> H;
vector <lli> V(N+2, 0);
for(lli i = 1; i < N+1; i++) cin >> V[i];
vector <int> M(N+2, false);
for(lli i = 1; i < N+1; i++) cin >> M[i];
// Delta sum.
for(lli i = 1; i < N+2; i++){
V[i] += V[i-1];
M[i] += M[i-1];
}
/*
cout << endl;
for(lli i = 0; i < N+2; i++){
cout << V[i] << " ";
}
cout << endl;
for(lli i = 0; i < N+2; i++){
cout << M[i] << " ";
}
cout << endl;
*/
// Two pointers opposite directional.
lli ans;
bool firstAns = true;
lli l = 0;
lli r = 1;
while(l < r){
lli dm = M[r]-M[l];
lli dv = V[r]-V[l];
if(dm <= H){
if(dm >= L){
if(firstAns){
ans = dv;
firstAns = false;
}
else ans = max(ans, dv);
}
r++;
}
else{
l++;
}
}
cout << ans << endl;
return 0;
}