Advertisement
moisey312

Task 9

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