Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- freopen("cowdance.in", "r", stdin);
- // freopen("cowdance.out", "w", stdout);
- int n, t;
- cin >> n >> t;
- int ar[n];
- for (int i = 0; i < n; i++) {
- cin >> ar[i];
- }
- int hi = n, lo = 1;
- int sol = n;
- while (lo <= hi) {
- int mid = lo + (hi - lo)/2;
- cout << "mid: "+to_string(mid) + ", {lo, hi} = {" + to_string(lo)+", "+to_string(hi) + "}" << endl;
- int time = 0, j = 0;
- priority_queue<int> pq;
- int size = 0;
- while (size < mid && j < n) {
- pq.push(-ar[j]);
- size++;
- j++;
- }
- while ((int) pq.size()) {
- cout << "[while] top: " + to_string(-pq.top()) ;
- time += max(0, -pq.top() - time);
- cout << ", time: " + to_string(time);
- pq.pop();
- if (j < n) {
- cout << " add j: "+to_string(j)+" val: "+to_string(ar[j]) + "+"+ to_string(time);
- pq.push(-(ar[j] + time));
- j++;
- }
- cout << endl;
- }
- if (time > t) {
- lo = mid + 1;
- cout << " [no] time: " +to_string(time) + " > " + to_string(t)+", new lo: "+to_string(lo);
- } else {
- sol = min(sol, mid);
- hi = mid - 1;
- cout << " [ok] time: "+to_string(time) + ", new hi: "+to_string(hi)+", sol: "+to_string(sol);
- }
- cout << endl;
- }
- cout << sol << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement