Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- using ll=long long;
- void Solve() {
- int n; cin >> n;
- vector<int> a(n);
- for (auto& x : a) cin >> x;
- int k; cin >> k;
- ll mx = INT_MIN;
- ll sm = 0;
- for (int i = 0; i < k; ++i) sm += a[i];
- for (int i = 0; i <= n - k; ++i) {
- mx = max(mx, sm);
- if (i < n - k) sm += a[i + k] - a[i];
- }
- cout << mx << "\n";
- }
- int main() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- Solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement