Alex_tz307

USACO 2017 January Contest, Silver Problem 1. Cow Dance Show

Dec 6th, 2020
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. // http://www.usaco.org/index.php?page=viewproblem2&cpid=690
  2. #include <bits/stdc++.h>
  3. #define int long long
  4.  
  5. using namespace std;
  6.  
  7. ifstream fin("cowdance.in");
  8. ofstream fout("cowdance.out");
  9.  
  10. int32_t main() {
  11.     int N, T;
  12.     fin >> N >> T;
  13.     vector<int> a(N + 1);
  14.     for(int i = 1; i <= N; ++i)
  15.         fin >> a[i];
  16.     int st = 1, dr = N, ans = -1;
  17.     while(st <= dr) {
  18.         int K = (st + dr) >> 1;
  19.         priority_queue < int > Q;
  20.         bool ok = true;
  21.         for(int i = 1; i <= N && ok; ++i) {
  22.             int time = 0;
  23.             if(Q.size() == K) {
  24.                 time = -Q.top();
  25.                 Q.pop();
  26.             }
  27.             if(time + a[i] > T)
  28.                 ok = false;
  29.             Q.push(-(time + a[i]));
  30.         }
  31.         if(ok) {
  32.             ans = K;
  33.             dr = K - 1;
  34.         }
  35.         else
  36.             st = K + 1;
  37.     }
  38.     fout << ans;
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment