Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define MAX 100007
- #define INF -1000000007
- using namespace std;
- int n, l, r;
- int arr[MAX], flag[MAX], ans[MAX];
- void build(){
- int resp = INF;
- for(int i = 0; i < n; i++){
- int sum = arr[i], cnt = flag[i];
- ans[i] = INF;
- for(int j = i+1; j < n; j++){
- if( cnt >= l && cnt <= r) ans[i] = max(ans[i], sum);
- sum += arr[j];
- cnt += flag[j];
- }
- if( cnt >= l && cnt <= r) ans[i] = max(ans[i], sum);
- resp = max(ans[i], resp);
- }
- if(resp == INF) printf("%d\n", 0);
- else printf("%d\n", resp);
- }
- int main(){
- scanf("%d %d %d", &n, &l, &r);
- for(int i = 0; i < n; i++) scanf("%d", &arr[i]);
- for(int i = 0; i < n; i++) scanf("%d", &flag[i]);
- build();
- return 0;
- }
Add Comment
Please, Sign In to add comment