vlatkovski

T

Jun 11th, 2017
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using std::cin;
  5. using std::cout;
  6. using std::endl;
  7. using std::vector;
  8.  
  9. int main() {
  10.     //N is the number of episodes, M is the watch time available
  11.     int n, m;
  12.     cin >> n >> m;
  13.  
  14.     vector<int> episodes(n);
  15.  
  16.     for (int i = 0; i < n; ++i) {
  17.         cin >> episodes[i];
  18.     }
  19.  
  20.     int max_watched = 0, end = 0, sum = 0;
  21.  
  22.     for (int start = 0; start < n; ++start) {
  23.         while (end < n && sum + episodes[end] <= m) {
  24.             sum += episodes[end];
  25.             end++;
  26.         }
  27.         if (end - start > max_watched) {
  28.             max_watched = end - start;
  29.         }
  30.         sum -= episodes[start];
  31.     }
  32.  
  33.     cout << max_watched << endl;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment