Advertisement
Josif_tepe

Untitled

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