Rentib

tarasy

Apr 1st, 2020
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int n, k, res = 0;
  5. cin >> n >> k;
  6. int t[n];
  7. for(int i = 0;i < n;i++)
  8. cin >> t[i];
  9. for(int poc = 0, kon = 0, kr = k, h = t[0];kon < n;kon++){
  10. kr -= max(t[kon] - h, 0);
  11. while(kr < 0)
  12. kr += max(t[++poc] - t[poc - 1], 0);
  13. res = max(res, kon - poc + 1);
  14. h = t[kon];
  15. }
  16. for(int poc = n - 1, kon = n - 1, kr = k, h = t[n - 1];kon >= 0;kon--){
  17. kr -= max(t[kon] - h, 0);
  18. while(kr < 0)
  19. kr += max(t[--poc] - t[poc + 1], 0);
  20. res = max(res, poc - kon + 1);
  21. h = t[kon];
  22. }
  23. cout << res;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment