Advertisement
Josif_tepe

Untitled

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