Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main(){
- int n, k, res = 0;
- cin >> n >> k;
- int t[n];
- for(int i = 0;i < n;i++)
- cin >> t[i];
- for(int poc = 0, kon = 0, kr = k, h = t[0];kon < n;kon++){
- kr -= max(t[kon] - h, 0);
- while(kr < 0)
- kr += max(t[++poc] - t[poc - 1], 0);
- res = max(res, kon - poc + 1);
- h = t[kon];
- }
- for(int poc = n - 1, kon = n - 1, kr = k, h = t[n - 1];kon >= 0;kon--){
- kr -= max(t[kon] - h, 0);
- while(kr < 0)
- kr += max(t[--poc] - t[poc + 1], 0);
- res = max(res, poc - kon + 1);
- h = t[kon];
- }
- cout << res;
- }
Advertisement
Add Comment
Please, Sign In to add comment