Advertisement
Rofyda_Elghadban1

Untitled

Sep 3rd, 2023
712
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.23 KB | None | 0 0
  1.  /*Rofyda Mohamed Hamed Hamed Elghadban*/
  2.  //#include <bits/stdc++.h>
  3.  #include <iostream>
  4.  #include <iomanip>
  5.  #include <cmath>
  6.  #include <algorithm>
  7.  #include <cstdlib>
  8.  #include <limits.h>
  9.  #include <string>
  10.  #include <vector>
  11.  #include <map>
  12.  #include <stack>
  13.  #include <set>
  14.  #include <deque>
  15.  #include <fstream>
  16.  #include <bitset>
  17.  #include <cmath>
  18.  #include <numeric>
  19.  #include <cstring>
  20.  #include <utility>
  21.  #include <queue>
  22.  
  23.  /***********************************************************************************/
  24.  
  25.  #define ll long long
  26.  #define ull unsigned long long
  27.  #define pi 3.141592654
  28.  #define NUM 1e18
  29.  #define Mod  1'000'000'007
  30.  #define fixed(n) fixed<<setprecision(n)
  31.  #define cin(v) for(auto &i:v) cin >> i ;
  32.  #define cout(v) for(auto &i:v) cout << i  <<" ";
  33.  #define Ceil(a,b) ((a/b)+(a%b ? 1 : 0))
  34.  #define vowel(x) (x=='e'||x=='a'||x=='i'||x=='o'||x=='u')
  35.  #define small(x) (x>=97&&x<=122)
  36.  #define capital(x) (x>=65&&x<=90)
  37.  #define Tolower(s) transform(s.begin(),s.end(),s.begin(),::tolower);
  38.  #define Toupper(s) transform(s.begin(),s.end(),s.begin(),::toupper);
  39.  #define all(v) ((v).begin()), ((v).end())
  40.  #define allr(v) ((v).rbegin()), ((v).rend())
  41.  #define updmax(a,b) a=max(a,b)
  42.  #define updmin(a,b) a=min(a,b)
  43.  #define ceil(a,b) ((a/b)+(a%b?1:0))
  44.  /* asc -> 1 2 3 ,des -> 3 2 1 */
  45.  
  46.  /***********************************************************************************/
  47.  
  48.  using namespace std;
  49.  
  50.  void Rofyda_Elghadban(){
  51.   #ifndef ONLINE_JUDGE  
  52.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  53.    #endif
  54.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  55.  }
  56.  
  57.  void solve(){
  58.  }
  59.  
  60.  int main(){
  61.   Rofyda_Elghadban();
  62.  //freopen("input.txt","r",stdin);
  63.  //freopen("output.txt","r",stdout);
  64.  
  65.  //solve();
  66.  
  67. //  int n;
  68. //  cin>>n;
  69. //  vector<int>v(n+1);
  70. //  v[0]=0;
  71. //  for(int i=1;i<n+1;i++){
  72. //   cin>>v[i];
  73. //  }
  74. //  ll prefix1[n+2]{},prefix2[n+2]{};
  75. //  for(int i=1;i<v.size()+1;i++){
  76. //   prefix1[i]=v[i]+prefix1[i-1];
  77. //  }
  78. //  sort(all(v));
  79. //  for(int i=1;i<v.size()+1;i++){
  80. //   prefix2[i]=v[i]+prefix2[i-1];
  81. //  }
  82. //  int q;
  83. //  cin>>q;
  84. //  while(q--){
  85. //   int t,l,r;
  86. //   cin>>t>>l>>r;
  87. //   if(t==1){
  88. //     cout<<prefix1[r]-prefix1[l-1]<<"\n";
  89. //   }else if(t==2){
  90. //     cout<<prefix2[r]-prefix2[l-1]<<"\n";
  91. //   }
  92. //  }
  93.  
  94. //  ll n,k,prefix[100001]{},prefix1[100001]{};
  95. //  cin>>n>>k;
  96. //  vector<ll>v1(n+1),v2(n+1),ans;
  97. //  v1[0]=0,v2[0]=0;
  98. //  for(ll i=1;i<n+1;i++){
  99. //   cin>>v1[i];
  100. //  }
  101. //  for(ll i=1;i<n+1;i++){
  102. //   cin>>v2[i];
  103. //  }
  104. //  for(ll i=1;i<n+1;i++){
  105. //   prefix[i]=v1[i]+prefix[i-1];
  106. //   ans.push_back(prefix[i]);
  107. //  }
  108. //  ll l=1,r=l+k-1,maxi=INT_MIN,idx=0,counter=0,p1=l,p2=r,counter1=0,maxiii=INT_MIN;
  109. //  for(ll i=1;i<v1.size()-k+1;i++){
  110. //   if(v2[i]==0){
  111. //     counter++;
  112. //     if(maxi<=prefix[r]-prefix[l-1]){
  113. //       maxi=max(maxi,prefix[r]-prefix[l-1]);
  114. //       idx=i;
  115. //       for(ll i=0;i<idx;i++){
  116. //         if(v2[i]==1){
  117. //           maxi=maxi+v1[i];
  118. //         }
  119. //       }
  120. //     }
  121. //   }
  122. //   // else{
  123. //   //   counter1++;
  124. //   // }
  125. //   l++;
  126. //   r++;
  127. //  }
  128. //  //if(counter>0&&counter!=n){
  129. //   cout<<maxi<<"\n";
  130. //  //}else if(counter1==n){
  131.  
  132. //   // if(k==1){
  133. //   //   sort(allr(ans));
  134. //   //   cout<<ans[0]<<"\n";
  135. //   // }else{
  136. //   //   cout<<prefix[p2]-prefix[p1]<<"\n";
  137. //   // }
  138. //   //cout<<ans[n-1]<<"\n";
  139. //  //}
  140. // //  else{
  141. // //   sort(allr(v1));
  142. // //   for(ll i=p1;i<=p2;i++){
  143. // //     // if(maxiii<=prefix[p2]-prefix[p1-1]){
  144. // //     //   maxiii=max(maxiii,prefix[p2]-prefix[p1-1]);
  145. // //     // }
  146. // //     prefix1[i]=v1[i]+prefix1[i-1];
  147. // //     // p1++;
  148. // //     // p2++;
  149. // //   }cout<<prefix1[k-1]<<"\n";
  150. // //  }
  151.  
  152. //  int n,k;
  153. //  cin>>n>>k;
  154. //  vector<int>v1(n+1),v2(n+1),ans;
  155. //  v1[0]=0,v2[0]=0;
  156. //  for(int i=1;i<n+1;i++){
  157. //   cin>>v1[i];
  158. //  }
  159. //  for(int i=1;i<n+1;i++){
  160. //   cin>>v2[i];
  161. //  }
  162. //  int l=1,r=l+k-1,prefix1[100001]{},maxi=INT_MIN,counter=0,prefix2[100001]{},idx=0;
  163. //  for(ll i=1;i<n+1;i++){
  164. //   prefix2[i]=v1[i]+prefix2[i-1];
  165. //   ans.push_back(prefix2[i]);
  166. //  }
  167.  
  168. //  for(int i=1;i<v1.size()-k+1;i++){
  169. //   prefix2[i]=prefix2[i-1]+v1[i];
  170. //   // if(v2[i]==0){
  171. //   //   counter++;
  172. //     //for(int j=l;j<=r;j++){
  173. //       if(maxi<=prefix1[r]-prefix1[l-1]){
  174. //         maxi=max(maxi,prefix1[r]-prefix1[l-1]);
  175. //         idx=i;
  176. //         for(ll i=0;i<idx;i++){
  177. //           if(v2[i]==1){
  178. //             maxi=maxi+v1[i];
  179. //           }
  180. //         }
  181. //       }
  182.  
  183. //     //}
  184. //   //}
  185. //   l++;
  186. //   r++;
  187. //  }
  188. //  if(counter>0){
  189. //   cout<<maxi<<"\n";
  190. //  }else{
  191. //   cout<<prefix2[n-1]<<"\n";
  192. //  }
  193.  
  194.  
  195.  int n,k;
  196.  cin>>n>>k;
  197.  vector<int>v1(n+1),v2(n+1),ans;
  198.  v1[0]=0,v2[0]=0;
  199.  for(int i=1;i<n+1;i++){
  200.   cin>>v1[i];
  201.  }
  202.  for(int i=1;i<n+1;i++){
  203.   cin>>v2[i];
  204.  }
  205.  int l=1,r=l+k-1,prefix1[n+2]{},sum=0,maxi=INT_MIN,idx1=0,idx2=0;
  206.  for(int i=1;i<n+1;i++){
  207.   prefix1[i]=v1[i]+prefix1[i-1];
  208.  }
  209.  for(int i=1;i<n+1;i++){
  210.   if(prefix1[r]-prefix1[l-1]>=maxi){
  211.     maxi=max(maxi,prefix1[r]-prefix1[l-1]);
  212.     idx1=i;
  213.     idx2=i+k-1;
  214.   }
  215.   l++;
  216.   r++;
  217.  }
  218.  //cout<<idx1<<" "<<idx2<<"\n";
  219.   for(int i=1;i<n+1;i++){
  220.   if(v2[i]==1){
  221.     sum+=v1[i];
  222.     if(i>=idx1&&i<=idx2){
  223.       sum-=v1[i];
  224.     }
  225.   }
  226.  }
  227.  //cout<<sum<<"\n";
  228.  cout<<maxi+sum<<"\n";
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  return 0;
  237. }
  238.  
  239.  
  240. /*
  241.  
  242. * * * * * * * *    * * * * * * * *    * * * * * * * *    *             *
  243. *             *    *             *    *                  *             *
  244. *             *    *             *    *                  *             *
  245. *             *    *             *    *                  *             *
  246. * * * * * * * *    *             *    * * * * * * * *    * * * * * * * *
  247. * *                *             *    *                                *
  248. *   *              *             *    *                                *
  249. *     *            *             *    *                                *
  250. *       *          *             *    *                                *
  251. *         *        *             *    *                                *
  252. *           *      *             *    *                                *    
  253. *             *    * * * * * * * *    *                  * * * * * * * *
  254.  
  255. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement