Advertisement
Zeinab_Hamdy

Untitled

Sep 26th, 2024 (edited)
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. //  #### Zeinab
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. #define nl "\n"
  5. #define fi first
  6. #define se second
  7. #define pb push_back
  8. #define ll long long
  9. #define RV return void
  10. #define sz(x) int(x.size())
  11. #define all(v) v.begin(), v.end()
  12. #define rall(v) v.rbegin(), v.rend()
  13. #define cin(v) for(auto&x:v) cin >> x;
  14. #define cout(v) for(auto&x:v) cout << x << " ";
  15.  
  16.  
  17.  
  18. void solve(){
  19.  
  20.    ll n , k ;
  21.     cin >> n >> k ;
  22.     vector <ll > hours(n) , days(n);
  23.     cin(hours);
  24.    ll cnt=1;
  25.     for(int i =0 ; i < n ; i++){
  26.         if(!i) {
  27.             days[i]=cnt;
  28.             continue;
  29.         }
  30.  
  31.         if(hours[i] <= hours[i-1]) cnt++;
  32.  
  33.         days[i] = cnt;;
  34.     }
  35.    ll ans = 0;
  36.     for(int i =0 ; i < n-1 ; i++){
  37.       ll lastIdx = min(n-1 , i + k +1);
  38.       ll currVal = (days[lastIdx] - days[i] -1 ) *24;
  39.        currVal = max(0ll , currVal);
  40.  
  41.        if(days[i] != days[lastIdx]){
  42.            currVal += 24 - hours[i] + hours[lastIdx]  -1 ;
  43.        }else{
  44.            currVal += hours[lastIdx] - hours[i] - 1;
  45.        }
  46.     //    cout << i << " " << lastIdx << " " << currVal << nl;
  47.        ans = max(ans , currVal);
  48.     }
  49.    ll idx = min(n-1 , k);
  50.     ans = max(ans , max(days[idx] - 2,0ll) * 24 + hours[idx]- 1);
  51.  
  52.     cout << ans ;
  53.    
  54.  
  55. }
  56.  
  57. int main(){
  58.     ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);  
  59.  
  60.  
  61.     int t=1;
  62.         // cin >> t ;
  63.     for(int i=1 ; i <= t ; i++){
  64.         // cout << "Case #"<< i <<": ";
  65.         solve();
  66.     }
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement