# Untitled

Sep 18th, 2023
851
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1.  #include <bits/stdc++.h>
2.
3.  #define ll long long
4.  #define ull unsigned long long
5.  #define pi 3.141592654
6.  #define NUM 1e18
7.  #define Mod  1'000'000'007
8.  #define fixed(n) fixed<<setprecision(n)
9.  #define cin(v) for(auto &i:v) cin >> i ;
10.  #define cout(v) for(auto &i:v) cout << i  <<" ";
11.  #define vowel(x) (x=='e'||x=='a'||x=='i'||x=='o'||x=='u')
12.  #define small(x) (x>=97&&x<=122)
13.  #define capital(x) (x>=65&&x<=90)
14.  #define Tolower(s) transform(s.begin(),s.end(),s.begin(),::tolower);
15.  #define Toupper(s) transform(s.begin(),s.end(),s.begin(),::toupper);
16.  #define all(v) ((v).begin()), ((v).end())
17.  #define allr(v) ((v).rbegin()), ((v).rend())
18.  #define updmax(a,b) a=max(a,b)
19.  #define updmin(a,b) a=min(a,b)
20.  #define ceil(a,b) ((a/b)+(a%b?1:0))
21.  /* asc -> 1 2 3 ,des -> 3 2 1 */
22.
23.  /***********************************************************************************/
24.
25.  using namespace std;
26.
28.   #ifndef ONLINE_JUDGE
29.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
30.    #endif
31.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
32.  }
33.
34.
35.  void solve(){
36.   int n,k;
37.   cin>>n>>k;
38.   vector<int>v(n+1),t(n+1),v2;
39.   for(int i=1;i<n+1;i++){
40.     cin>>v[i];
41.   }
42.   for(int i=1;i<n+1;i++){
43.     cin>>t[i];
44.   }
45.   for(int i=0;i<n+1;i++){
46.     if(t[i]==1){
47.       v2.push_back(v[i]);
48.     }else if(t[i]==0||i==0){
49.       v2.push_back(0);
50.     }
51.   }
52.   int prefix1[100001]{},prefix2[100001]{},pre=0;
53.   for(int i=1;i<n+1;i++){
54.     prefix1[i]=v[i]+prefix1[i-1];
55.   }
56.   for(int i=1;i<n+1;i++){
57.     prefix2[i]=v2[i]+prefix2[i-1];
58.   }
59.   int l=1,r=l+k-1,maxi=INT_MIN,s1=0,s=0,s2=0;
60.   for(int i=1;i<n+1;i++){
61.     s1=prefix2[l-1]-prefix2[0];
62.     s=prefix1[r]-prefix1[l-1];
63.     s2=prefix2[n]-prefix2[r-1];
64.     maxi=max(maxi,(s1+s+s2));
65.     if(r<=n){
66.       l++;
67.       r++;
68.       s1=0;
69.       s=0;
70.       s2=0;
71.     }
72.   }
73.   cout<<maxi<<"\n";
74.  }
75.
76.
77.  int main(){