Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // #### Zeinab
- #include<bits/stdc++.h>
- using namespace std;
- #define nl "\n"
- #define fi first
- #define se second
- #define pb push_back
- #define ll long long
- #define RV return void
- #define sz(x) int(x.size())
- #define all(v) v.begin(), v.end()
- #define rall(v) v.rbegin(), v.rend()
- #define cin(v) for(auto&x:v) cin >> x;
- #define cout(v) for(auto&x:v) cout << x << " ";
- void solve(){
- ll n , k ;
- cin >> n >> k ;
- vector <ll > hours(n) , days(n);
- cin(hours);
- ll cnt=1;
- for(int i =0 ; i < n ; i++){
- if(!i) {
- days[i]=cnt;
- continue;
- }
- if(hours[i] <= hours[i-1]) cnt++;
- days[i] = cnt;;
- }
- ll ans = 0;
- for(int i =0 ; i < n-1 ; i++){
- ll lastIdx = min(n-1 , i + k +1);
- ll currVal = (days[lastIdx] - days[i] -1 ) *24;
- currVal = max(0ll , currVal);
- if(days[i] != days[lastIdx]){
- currVal += 24 - hours[i] + hours[lastIdx] -1 ;
- }else{
- currVal += hours[lastIdx] - hours[i] - 1;
- }
- // cout << i << " " << lastIdx << " " << currVal << nl;
- ans = max(ans , currVal);
- }
- ll idx = min(n-1 , k);
- ans = max(ans , max(days[idx] - 2,0ll) * 24 + hours[idx]- 1);
- cout << ans ;
- }
- int main(){
- ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
- int t=1;
- // cin >> t ;
- for(int i=1 ; i <= t ; i++){
- // cout << "Case #"<< i <<": ";
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement