Advertisement
Josif_tepe

Untitled

Jul 18th, 2024
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. int main(){
  5.    int n, k;
  6.    cin >> n >> k;
  7.  
  8.    int niza[n];
  9.    for(int i = 0; i < n; i++) {
  10.     cin >> niza[i];
  11.    }
  12.  
  13.    int sum = 0;
  14.    for(int i = 0; i < k; i++) {
  15.     sum += niza[i];
  16.    }
  17.    cout << sum << " ";
  18.  
  19.    for(int i = k; i < n; i++) {
  20.     sum += niza[i];
  21.     sum -= niza[i - k];
  22.     cout << sum << " ";
  23.    }
  24.    
  25.    
  26.    
  27.  return 0;
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement