Advertisement
Josif_tepe

Untitled

Jul 20th, 2024
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 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.   int sum = 0;
  13.   for(int i = 0; i < k; i++) {
  14.     sum += niza[i];
  15.   }
  16.   cout << sum << " ";
  17.  
  18.   for(int i = k; i < n; i++) {
  19.     sum += niza[i];
  20.     sum -= niza[i - k];
  21.  
  22.     cout << sum << " ";
  23.   }
  24.    
  25.    
  26.    
  27.  return 0;
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement