Manioc

sequencia

Jun 26th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define MAX 100007
  3. #define INF -1000000007
  4.  
  5. using namespace std;
  6. int n, l, r;
  7. int arr[MAX], flag[MAX], ans[MAX];
  8.  
  9. void build(){
  10.     int resp = INF;
  11.     for(int i = 0; i < n; i++){
  12.         int sum = arr[i], cnt = flag[i];
  13.         ans[i] = INF;
  14.         for(int j = i+1; j < n; j++){
  15.             if( cnt >= l && cnt <= r) ans[i] = max(ans[i], sum);
  16.             sum += arr[j];
  17.             cnt += flag[j];
  18.         }
  19.         if( cnt >= l && cnt <= r) ans[i] = max(ans[i], sum);
  20.         resp = max(ans[i], resp);
  21.     }
  22.     if(resp == INF) printf("%d\n", 0);
  23.     else printf("%d\n", resp);
  24. }
  25. int main(){
  26.     scanf("%d %d %d", &n, &l, &r);
  27.     for(int i = 0; i < n; i++) scanf("%d", &arr[i]);
  28.     for(int i = 0; i < n; i++) scanf("%d", &flag[i]);
  29.     build();
  30.     return 0;
  31. }
Add Comment
Please, Sign In to add comment