Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- #include <cstdlib>
- #include <algorithm>
- #include <cmath>
- #include <iomanip>
- #include <numeric>
- #include <vector>
- using namespace std;
- #define ll long long
- void sherry()
- {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- int main()
- {
- sherry();
- ll n, k, max_num = INT_MIN, sum = 0;
- cin >> n >> k;
- ll arr1[n + 2]{}, arr2[n + 2]{1};
- for (ll i = 0; i < n; i++)
- {
- cin >> arr1[i];
- }
- for (ll i = 0; i < n - k + 1; i++)
- {
- cin >> arr2[i];
- }
- for (ll i = 0; i < n; i++)
- {
- if (arr2[i] == 1)
- sum += arr1[i];
- else
- {
- ll number = 0;
- for (ll j = i; j < i + k && j < n; j++)
- {
- if (arr2[j] == 0)
- number += arr1[j];
- }
- max_num = max(max_num, number);
- }
- }
- cout << sum + max_num;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement