Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- int main() {
- int n;
- int sum = 0;
- int sum_max = 0;
- cin >> n;
- vector<int> a(n);
- for (int i = 0; i < n; i++) {
- cin >> a[i];
- }
- for(int i = 0; i<n && i<3; i++){
- sum += a[i];
- }
- sum_max = sum;
- for (int i = 3; i < n; i++) {
- sum = sum - a[i-3] + a[i];
- if(sum>sum_max){
- sum_max = sum;
- }
- }
- cout << sum_max;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement