Advertisement
tepyotin2

Cow Dance Show

Oct 10th, 2023
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4.     freopen("cowdance.in", "r", stdin);
  5.     // freopen("cowdance.out", "w", stdout);
  6.     int n, t;
  7.     cin >> n >> t;
  8.     int ar[n];
  9.     for (int i = 0; i < n; i++) {
  10.         cin >> ar[i];
  11.     }
  12.     int hi = n, lo = 1;
  13.     int sol = n;
  14.     while (lo <= hi) {
  15.         int mid = lo + (hi - lo)/2;
  16.         cout << "mid: "+to_string(mid) + ", {lo, hi} = {" + to_string(lo)+", "+to_string(hi) + "}" << endl;
  17.         int time = 0, j = 0;
  18.         priority_queue<int> pq;
  19.         int size = 0;
  20.         while (size < mid && j < n) {
  21.             pq.push(-ar[j]);
  22.             size++;
  23.             j++;
  24.         }
  25.         while ((int) pq.size()) {
  26.             cout << "[while] top: " + to_string(-pq.top()) ;
  27.             time += max(0, -pq.top() - time);
  28.             cout <<  ", time: " + to_string(time);
  29.             pq.pop();
  30.             if (j < n) {
  31.                 cout << " add j: "+to_string(j)+" val: "+to_string(ar[j]) + "+"+ to_string(time);
  32.                 pq.push(-(ar[j] + time));
  33.                 j++;
  34.             }
  35.             cout << endl;
  36.         }
  37.         if (time > t) {
  38.             lo = mid + 1;
  39.             cout << " [no] time: " +to_string(time) + " > " + to_string(t)+", new lo: "+to_string(lo);
  40.         } else {
  41.             sol = min(sol, mid);
  42.             hi = mid - 1;
  43.             cout <<  " [ok] time: "+to_string(time)  + ", new hi: "+to_string(hi)+", sol: "+to_string(sol);
  44.         }
  45.         cout << endl;
  46.     }
  47.     cout << sol << '\n';
  48. }
  49.  
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement