Advertisement
sherry_ahmos

Untitled

Apr 25th, 2022
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <cstdlib>
  4. #include <algorithm>
  5. #include <cmath>
  6. #include <iomanip>
  7. #include <numeric>
  8. #include <vector>
  9.  
  10. using namespace std;
  11. #define ll long long
  12. void sherry()
  13. {
  14.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  15. #ifndef ONLINE_JUDGE
  16.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  17. #endif
  18. }
  19. int main()
  20. {
  21.     sherry();
  22.     ll n, k, max_num = INT_MIN, sum = 0;
  23.     cin >> n >> k;
  24.     ll arr1[n + 2]{}, arr2[n + 2]{1};
  25.     for (ll i = 0; i < n; i++)
  26.     {
  27.         cin >> arr1[i];
  28.     }
  29.     for (ll i = 0; i < n - k + 1; i++)
  30.     {
  31.         cin >> arr2[i];
  32.     }
  33.     for (ll i = 0; i < n; i++)
  34.     {
  35.         if (arr2[i] == 1)
  36.             sum += arr1[i];
  37.         else
  38.         {
  39.             ll number = 0;
  40.             for (ll j = i; j < i + k && j < n; j++)
  41.             {
  42.                 if (arr2[j] == 0)
  43.                     number += arr1[j];
  44.             }
  45.             max_num = max(max_num, number);
  46.         }
  47.     }
  48.     cout << sum + max_num;
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement